aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/populate
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/populate')
-rw-r--r--pkgs/populate/src/rsync.rs31
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> {