diff options
| author | tv <tv@krebsco.de> | 2026-11-30 14:49:44 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-30 14:49:44 +0000 |
| commit | b3e1b76e2842e6b6d74789aa8b0f3ed9e2c005a0 (patch) | |
| tree | 5fd06da5cbc7dfd94bd62778121ddc2bbf523750 /pkgs/populate | |
| parent | b5a3510bdebd7a0ce2242ad34b7be81d430b7c35 (diff) | |
populate: ask rsync for its version only if a source has filter files
The check for .rsync-filter files rsync can't read ran rsync --version
for each file source, also for sources without any filter files, where
it doesn't matter. It looks for filter files first, and asks rsync for
its version only then, and only once per run. A no-op run of 50 file
sources takes 0.3 s less locally.
Diffstat (limited to 'pkgs/populate')
| -rw-r--r-- | pkgs/populate/src/rsync.rs | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/pkgs/populate/src/rsync.rs b/pkgs/populate/src/rsync.rs index f943d0e..ccb2400 100644 --- a/pkgs/populate/src/rsync.rs +++ b/pkgs/populate/src/rsync.rs @@ -178,17 +178,13 @@ fn changed_path(line: &str) -> Option<String> { /// the files it transfers with --insecure-links if it's true, both with a /// warning. Returns whether rsync needs --insecure-links. fn insecure_links(context: &Context, config: &Config, source: &str) -> Result<bool> { - let version_line = run::output(Command::new("rsync").arg("--version"))?; - let version = version_line - .lines() - .next() - .and_then(|line| line.split_whitespace().nth(2)) - .unwrap_or("") - .to_string(); // Also with older versions of rsync, so a source that's missing, or // that contains a directory find can't read, fails before rsync runs. - let filtered = filtered(source)?; - if !version_at_least(&version, "3.5.0") || !filtered { + if !filtered(source)? { + return Ok(false); + } + let version = rsync_version()?; + if !version_at_least(&version, "3.5.0") { return Ok(false); } // A dry run of the same transfer, as far as filtering goes. @@ -291,6 +287,23 @@ fn parent(path: &str) -> String { } } +/// The version of the rsync in PATH, from rsync --version, which runs once +/// per run, not once for each source. +fn rsync_version() -> Result<String> { + static VERSION: std::sync::OnceLock<String> = std::sync::OnceLock::new(); + if let Some(version) = VERSION.get() { + return Ok(version.clone()); + } + let output = run::output(Command::new("rsync").arg("--version"))?; + let version = output + .lines() + .next() + .and_then(|line| line.split_whitespace().nth(2)) + .unwrap_or("") + .to_string(); + Ok(VERSION.get_or_init(|| version).clone()) +} + /// Like sort -V: whether version is at least minimum. fn version_at_least(version: &str, minimum: &str) -> bool { let parts = |v: &str| -> Vec<u64> { |
