Skip to content

Commit

Permalink
better errors, mkdirp when importing
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseditson committed Feb 16, 2025
1 parent 4acb2e5 commit 22c5770
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,12 +384,13 @@ impl<F: FileSystemAPI + Clone + Debug> Archival<F> {
event.object
)))?;
self.fs_mutex.with_fs(|fs| {
let path = self
let obj_dir = self
.site
.manifest
.objects_dir
.join(Path::new(&event.object))
.join(Path::new(&format!("{}.toml", event.filename)));
.join(Path::new(&event.object));
fs.create_dir_all(&obj_dir)?;
let path = obj_dir.join(Path::new(&format!("{}.toml", event.filename)));
if fs.exists(&path)? {
return Err(ArchivalError::new(&format!(
"cannod add {} named {}, file already exists.",
Expand All @@ -410,7 +411,9 @@ impl<F: FileSystemAPI + Clone + Debug> Archival<F> {
.into());
}
let object = Object::from_def(obj_def, &event.filename, event.order, event.values)?;
fs.write_str(&path, object.to_toml()?)?;
fs.write_str(&path, object.to_toml()?).map_err(|error| {
ArchivalError::new(&format!("failed writing to {}: {}", path.display(), error))
})?;
self.site.invalidate_file(&path);
Ok(())
})?;
Expand Down

0 comments on commit 22c5770

Please # to comment.