From c13d8f2ee3fcdb5beb6b8c9c5e8b1d421464ca86 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sat, 3 Jul 2021 18:35:51 +0200 Subject: [PATCH] [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. --- CHANGELOG.md | 3 +++ tools/yabridgectl/src/actions.rs | 12 ++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 63c21309..7b0b445f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 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! +- 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 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 diff --git a/tools/yabridgectl/src/actions.rs b/tools/yabridgectl/src/actions.rs index 7c2da1f2..110b2d0d 100644 --- a/tools/yabridgectl/src/actions.rs +++ b/tools/yabridgectl/src/actions.rs @@ -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(); + } } }