mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-07 03:50:11 +02:00
[yabridgectl] Recursively prune empty directories
If pruning results in a directory becoming empty, then we should remove that directory. This approach won't touch any directories that we aren't pruning from.
This commit is contained in:
@@ -451,11 +451,10 @@ pub fn do_sync(config: &mut Config, options: &SyncOptions) -> Result<()> {
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: Prune empty subdirectories
|
||||
for file in orphan_files {
|
||||
println!("- {}", file.path().display());
|
||||
if options.prune {
|
||||
match file {
|
||||
match &file {
|
||||
NativeFile::Regular(path) | NativeFile::Symlink(path) => {
|
||||
utils::remove_file(path)?;
|
||||
}
|
||||
@@ -463,6 +462,15 @@ pub fn do_sync(config: &mut Config, options: &SyncOptions) -> Result<()> {
|
||||
utils::remove_dir_all(path)?;
|
||||
}
|
||||
}
|
||||
|
||||
// If the directory `file` was in is now empty, then we'll also recursively prune
|
||||
// the empty subdirectory
|
||||
let mut parent_dir = file.path().parent();
|
||||
while let Some(dir) =
|
||||
parent_dir.and_then(|dir| fs::remove_dir(dir).ok().map(|_| dir))
|
||||
{
|
||||
parent_dir = dir.parent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user