mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-28 11:29:25 +00:00
Fix bugs in FakeFs::{remove_dir,rename}
This commit is contained in:
parent
4b1c46fa45
commit
ecb847a027
1 changed files with 12 additions and 10 deletions
|
@ -493,7 +493,7 @@ impl Fs for FakeFs {
|
|||
});
|
||||
|
||||
for (relative_path, entry) in removed {
|
||||
let new_path = target.join(relative_path);
|
||||
let new_path = normalize_path(&target.join(relative_path));
|
||||
state.entries.insert(new_path, entry);
|
||||
}
|
||||
|
||||
|
@ -501,13 +501,15 @@ impl Fs for FakeFs {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
async fn remove_dir(&self, path: &Path, options: RemoveOptions) -> Result<()> {
|
||||
let path = normalize_path(path);
|
||||
async fn remove_dir(&self, dir_path: &Path, options: RemoveOptions) -> Result<()> {
|
||||
let dir_path = normalize_path(dir_path);
|
||||
let mut state = self.state.lock().await;
|
||||
state.validate_path(&path)?;
|
||||
if let Some(entry) = state.entries.get(&path) {
|
||||
state.validate_path(&dir_path)?;
|
||||
if let Some(entry) = state.entries.get(&dir_path) {
|
||||
if !entry.metadata.is_dir {
|
||||
return Err(anyhow!("cannot remove {path:?} because it is not a dir"));
|
||||
return Err(anyhow!(
|
||||
"cannot remove {dir_path:?} because it is not a dir"
|
||||
));
|
||||
}
|
||||
|
||||
if !options.recursive {
|
||||
|
@ -517,14 +519,14 @@ impl Fs for FakeFs {
|
|||
.filter(|path| path.starts_with(path))
|
||||
.count();
|
||||
if descendants > 1 {
|
||||
return Err(anyhow!("{path:?} is not empty"));
|
||||
return Err(anyhow!("{dir_path:?} is not empty"));
|
||||
}
|
||||
}
|
||||
|
||||
state.entries.retain(|path, _| !path.starts_with(path));
|
||||
state.emit_event(&[path]).await;
|
||||
state.entries.retain(|path, _| !path.starts_with(&dir_path));
|
||||
state.emit_event(&[dir_path]).await;
|
||||
} else if !options.ignore_if_not_exists {
|
||||
return Err(anyhow!("{path:?} does not exist"));
|
||||
return Err(anyhow!("{dir_path:?} does not exist"));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in a new issue