From 9ae0e8ca3836384c417d5ddb0cedc17cff45309d Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sat, 12 Jun 2021 11:38:33 +0200 Subject: [PATCH] [yabridgectl] Use reflinks instead of copies Whenever available. This should speed up the copying process while also reducing the amount of disk space wasted on Btrfs and XFS filesystems. --- CHANGELOG.md | 7 +++++++ tools/yabridgectl/Cargo.lock | 11 +++++++++++ tools/yabridgectl/Cargo.toml | 1 + tools/yabridgectl/src/actions.rs | 2 +- tools/yabridgectl/src/utils.rs | 9 +++++---- 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ecc4d45..4d5cf8de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,13 @@ Versioning](https://semver.org/spec/v2.0.0.html). serialized correctly. No plugins seem to actually use these, so it should not have caused any issues. +### yabridgectl + +- 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 + Btrfs or XFS. + ## [3.3.1] - 2021-06-09 ### Added diff --git a/tools/yabridgectl/Cargo.lock b/tools/yabridgectl/Cargo.lock index 7ab95213..4a06aeb7 100644 --- a/tools/yabridgectl/Cargo.lock +++ b/tools/yabridgectl/Cargo.lock @@ -387,6 +387,16 @@ dependencies = [ "redox_syscall", ] +[[package]] +name = "reflink" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc585ec28b565b4c28977ce8363a6636cedc280351ba25a7915f6c9f37f68cbe" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "rustyline" version = "6.3.0" @@ -625,6 +635,7 @@ dependencies = [ "lazy_static", "promptly", "rayon", + "reflink", "serde", "serde_derive", "textwrap 0.11.0", diff --git a/tools/yabridgectl/Cargo.toml b/tools/yabridgectl/Cargo.toml index dc8eee28..0decd8a9 100644 --- a/tools/yabridgectl/Cargo.toml +++ b/tools/yabridgectl/Cargo.toml @@ -17,6 +17,7 @@ colored = "2.0.0" is_executable = "0.1.2" lazy_static = "1.4.0" promptly = "0.3.0" +reflink = "0.1.3" rayon = "1.3.1" serde = "1.0.114" serde_derive = "1.0.114" diff --git a/tools/yabridgectl/src/actions.rs b/tools/yabridgectl/src/actions.rs index 7dcfef6b..5eceefa8 100644 --- a/tools/yabridgectl/src/actions.rs +++ b/tools/yabridgectl/src/actions.rs @@ -501,7 +501,7 @@ fn install_file( match method { InstallationMethod::Copy => { - utils::copy(from, to)?; + utils::copy_or_reflink(from, to)?; } InstallationMethod::Symlink => { utils::symlink(from, to)?; diff --git a/tools/yabridgectl/src/utils.rs b/tools/yabridgectl/src/utils.rs index 0cb75bcc..cbb187b5 100644 --- a/tools/yabridgectl/src/utils.rs +++ b/tools/yabridgectl/src/utils.rs @@ -37,11 +37,12 @@ use crate::files::NativeFile; /// moment without causing issues. const YABRIDGE_HOST_EXPECTED_OUTPUT_PREFIX: &str = "Usage: yabridge-"; -/// Wrapper around [`std::fs::copy()`](std::fs::copy) with a human readable error message. -pub fn copy, Q: AsRef>(from: P, to: Q) -> Result { - fs::copy(&from, &to).with_context(|| { +/// Wrapper around [`reflink::reflink_or_copy()`](reflink::reflink_or_copy) with a human readable +/// error message. +pub fn copy_or_reflink, Q: AsRef>(from: P, to: Q) -> Result> { + reflink::reflink_or_copy(&from, &to).with_context(|| { format!( - "Error copying '{}' to '{}'", + "Error reflinking '{}' to '{}'", from.as_ref().display(), to.as_ref().display() )