Skip to content

Commit

Permalink
Don't nest singletons in FS provider (#5342)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbastian authored Aug 9, 2024
1 parent ad41da6 commit 3c0782b
Show file tree
Hide file tree
Showing 150 changed files with 16 additions and 8 deletions.
16 changes: 11 additions & 5 deletions provider/fs/src/export/fs_exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,23 @@ impl DataExporter for FilesystemExporter {
if !id.marker_attributes.is_empty() {
path_buf.push(id.marker_attributes.as_str());
}
let mut path_buf = path_buf.into_os_string();
write!(&mut path_buf, "/{}", id.locale).expect("infallible");
let mut path_buf = PathBuf::from(path_buf);
path_buf.set_extension(self.manifest.file_extension);

#[allow(clippy::unwrap_used)] // has parent by construction
let parent_dir = path_buf.parent().unwrap();

fs::create_dir_all(parent_dir)
.map_err(|e| DataError::from(e).with_path_context(parent_dir))?;

if !marker.is_singleton {
fs::create_dir_all(&path_buf)
.map_err(|e| DataError::from(e).with_path_context(&path_buf))?;
let mut string_path = path_buf.into_os_string();
write!(&mut string_path, "/{}", id.locale).expect("infallible");
path_buf = PathBuf::from(string_path);
}

path_buf.set_extension(self.manifest.file_extension);

let mut file: Box<dyn std::io::Write> = if self.serializer.is_text_format() {
Box::new(crlify::BufWriterWithLineEndingFix::new(
fs::File::create(&path_buf)
Expand All @@ -141,7 +147,7 @@ impl DataExporter for FilesystemExporter {
fn flush(&self, marker: DataMarkerInfo) -> Result<(), DataError> {
let mut path_buf = self.root.join(marker.path.as_str());

if !path_buf.exists() {
if !marker.is_singleton && !path_buf.exists() {
fs::create_dir_all(&path_buf)
.map_err(|e| DataError::from(e).with_path_context(&path_buf))?;
path_buf.push(".empty");
Expand Down
8 changes: 5 additions & 3 deletions provider/fs/src/fs_data_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@ impl FsDataProvider {
path.push(req.id.marker_attributes.as_str());
}
}
let mut path = path.into_os_string();
write!(&mut path, "/{}", req.id.locale).expect("infallible");
let mut path = PathBuf::from(path);
if !marker.is_singleton {
let mut string_path = path.into_os_string();
write!(&mut string_path, "/{}", req.id.locale).expect("infallible");
path = PathBuf::from(string_path);
}
path.set_extension(self.manifest.file_extension);
if !path.exists() {
return Err(DataErrorKind::IdentifierNotFound.with_req(marker, req));
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 3c0782b

Please sign in to comment.