[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:
Robbert van der Helm
2021-07-03 18:35:51 +02:00
parent 70c40970aa
commit c13d8f2ee3
2 changed files with 13 additions and 2 deletions
+3
View File
@@ -96,6 +96,9 @@ Versioning](https://semver.org/spec/v2.0.0.html).
makes it easy to switch from the 64-bit version of a plugin to the 32-bit makes it easy to switch from the 64-bit version of a plugin to the 32-bit
version, or from a 64-bit version of yabridge to the 32-bit version. I don't version, or from a 64-bit version of yabridge to the 32-bit version. I don't
know why you would want to do either of those things, but now you can! know why you would want to do either of those things, but now you can!
- If pruning causes a directory to be empty, then the empty directory will be
removed. This avoids having your plugin directories littered with empty
directories.
- Copies of `libyabridge-vst2.so` and `libyabridge-vst3.so` are now reflinked - Copies of `libyabridge-vst2.so` and `libyabridge-vst3.so` are now reflinked
when supported by the file system. This speeds up the file coyping process when supported by the file system. This speeds up the file coyping process
while also reducing the amount of disk space used for yabridge when using while also reducing the amount of disk space used for yabridge when using
+10 -2
View File
@@ -451,11 +451,10 @@ pub fn do_sync(config: &mut Config, options: &SyncOptions) -> Result<()> {
); );
} }
// TODO: Prune empty subdirectories
for file in orphan_files { for file in orphan_files {
println!("- {}", file.path().display()); println!("- {}", file.path().display());
if options.prune { if options.prune {
match file { match &file {
NativeFile::Regular(path) | NativeFile::Symlink(path) => { NativeFile::Regular(path) | NativeFile::Symlink(path) => {
utils::remove_file(path)?; utils::remove_file(path)?;
} }
@@ -463,6 +462,15 @@ pub fn do_sync(config: &mut Config, options: &SyncOptions) -> Result<()> {
utils::remove_dir_all(path)?; 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();
}
} }
} }