aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/populate/src/rsync.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-20 01:48:55 +0000
committertv <tv@krebsco.de>2026-11-20 01:48:55 +0000
commit7837a236e728988fcd501917444828b790c367f9 (patch)
treef2f3b91ffe0fd7f60f71f12c5f4f871c92916665 /pkgs/populate/src/rsync.rs
parentf02b09eae7e806f2fe9caa26b4975b94351d7e27 (diff)
populate: lock files rewritten in place change only if they differ
A file or git source whose lock file the flakes step rewrites in place gets the original back from delivering it, on every run, from rsync, or from git reset, which also printed HEAD is now at, and Nix printed that it updates the lock file, so the record said the source changed on every run. Populate keeps a copy of the rewritten lock file in .populate/locks/<name>, and the flakes step compares with it, printing what Nix says about the lock file, and changed, only if it differs. Delivering such a source doesn't count bringing back the lock file: rsync returns the paths of what it changed, and the git source's script takes the lock file's path, and resets quietly if that's all that differs. relock also checks that the second, unchanged, run prints nothing about lock files, and says nothing changed, now for rewriting in place too.
Diffstat (limited to 'pkgs/populate/src/rsync.rs')
-rw-r--r--pkgs/populate/src/rsync.rs59
1 files changed, 40 insertions, 19 deletions
diff --git a/pkgs/populate/src/rsync.rs b/pkgs/populate/src/rsync.rs
index 7858e4a..1b46723 100644
--- a/pkgs/populate/src/rsync.rs
+++ b/pkgs/populate/src/rsync.rs
@@ -84,8 +84,14 @@ impl Config {
}
/// Transfers source_path, a directory's contents or a file, to path on the
-/// target, returning whether that changed anything there.
-pub fn transfer(context: &Context, config: &Config, source_path: &str, path: &str) -> Result<bool> {
+/// target, returning the paths, relative to path, of what that changed
+/// there.
+pub fn transfer(
+ context: &Context,
+ config: &Config,
+ source_path: &str,
+ path: &str,
+) -> Result<Vec<String>> {
context.run(&sh::break_hard_links(), &[path, &context.name(path)])?;
let mut source = source_path.to_string();
if Path::new(source_path).is_dir() {
@@ -124,23 +130,33 @@ pub fn transfer(context: &Context, config: &Config, source_path: &str, path: &st
command.arg("--delete-excluded");
}
command.arg(&source).arg(context.rsync_destination(path));
- let mut changed = false;
+ let mut changed = Vec::new();
run::lines(&mut command, |line| {
- changed |= itemizes_change(line);
+ changed.extend(changed_path(line));
eprintln!("{line}");
})?;
Ok(changed)
}
-/// Whether a line rsync prints itemizes a change: what --itemize-changes
-/// prints for an item, eleven characters, the second the type of the item,
-/// or *deleting, followed by a blank.
-fn itemizes_change(line: &str) -> bool {
- let Some((item, _)) = line.split_once(' ') else {
- return false;
+/// The path of what a line rsync prints itemizes a change of: what
+/// --itemize-changes prints for an item, eleven characters, the second the
+/// type of the item, or *deleting, followed by a blank, and the path, which
+/// the sizes follow for items, and a symlink's target, after ->.
+fn changed_path(line: &str) -> Option<String> {
+ let (item, rest) = line.split_once(' ')?;
+ if item == "*deleting" {
+ return Some(rest.trim_start().to_string());
+ }
+ if item.len() != 11 || !matches!(item.as_bytes()[1], b'f' | b'd' | b'L' | b'D' | b'S') {
+ return None;
+ }
+ let (path, _sizes) = rest.rsplit_once(' ')?;
+ let path = if item.as_bytes()[1] == b'L' {
+ path.split_once(" -> ").map_or(path, |(path, _)| path)
+ } else {
+ path
};
- item == "*deleting"
- || item.len() == 11 && matches!(item.as_bytes()[1], b'f' | b'd' | b'L' | b'D' | b'S')
+ Some(path.to_string())
}
/// rsync 3.5.0 and later open .rsync-filter files with a stricter walk than
@@ -315,13 +331,18 @@ mod tests {
use super::*;
#[test]
- fn itemized_changes() {
- assert!(itemizes_change(">f.st...... flake.nix 82/39"));
- assert!(itemizes_change("cd+++++++++ .git/objects/25/ 0/4.00K"));
- assert!(itemizes_change(".f..t...... x 0/1"));
- assert!(itemizes_change("*deleting old"));
- assert!(!itemizes_change("skipping non-regular file \"x\""));
- assert!(!itemizes_change("sent 10 bytes"));
+ fn changed_paths() {
+ let path = |line| changed_path(line);
+ assert_eq!(
+ path(">f.st...... flake.nix 82/39").as_deref(),
+ Some("flake.nix")
+ );
+ assert_eq!(path("cd+++++++++ a b/ 0/4.00K").as_deref(), Some("a b/"));
+ assert_eq!(path(".f..t...... x 0/1").as_deref(), Some("x"));
+ assert_eq!(path("cL+++++++++ l -> t 0/0").as_deref(), Some("l"));
+ assert_eq!(path("*deleting old").as_deref(), Some("old"));
+ assert_eq!(path("skipping non-regular file \"x\""), None);
+ assert_eq!(path("sent 10 bytes"), None);
}
#[test]