Skip to content

Commit

Permalink
allow imports to empty dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
rasviitanen authored and Rasmus Viitanen committed Oct 3, 2021
1 parent 8ba84fa commit 85ca11b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions synth/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ impl Cli {
self.store.save_collection_path(&path, collection, content)?;
Ok(())
}
} else if self.store.ns_exists(&path) {
} else if self.store.ns_exists(&path) && !self.store.ns_is_empty_dir(&path) {
Err(anyhow!(
"The directory at `{}` already exists. Will not import into an existing directory.",
"The directory at `{}` already exists and is not empty. Will not import into an existing directory.",
path.display()
))
} else {
Expand Down
5 changes: 5 additions & 0 deletions synth/src/cli/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ impl Store {
self.ns_path(namespace).exists()
}

pub fn ns_is_empty_dir(&self, namespace: &Path) -> bool {
self.ns_path(namespace).is_dir()
&& self.ns_path(namespace).read_dir().map(|mut dir| dir.next().is_none()).unwrap_or_default()
}

pub fn collection_exists(&self, namespace: &Path, collection: &Name) -> bool {
self.collection_path(namespace, collection).exists()
}
Expand Down

0 comments on commit 85ca11b

Please sign in to comment.