aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/populate/src
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-12-01 02:47:32 +0000
committertv <tv@krebsco.de>2026-12-01 04:06:17 +0000
commit3aff9c58c68d6882294e6586ddb384709ce95abe (patch)
treef7f7d13dec077dc21858f56a3a990c483f5f22c8 /pkgs/populate/src
parentcf26dc1f928e9839123bedd1693d792bbb418312 (diff)
populate: probe passage and pass sources too
A passage source ran rsync on every run, about a dozen round trips to a remote target, and a pass source a command reading .pass_info, which tells whether the passwords changed. The probe lists the target paths of passage sources too, and reads what pass sources' .pass_info contains. After decrypting, a passage source lists its working directory with find, whose files have the times of their .age files and fixed modes, and doesn't run rsync if the listings are the same; Delivery::transfer does that for any source the probe listed. A pass source takes .pass_info from the probe.
Diffstat (limited to 'pkgs/populate/src')
-rw-r--r--pkgs/populate/src/populate.rs31
-rw-r--r--pkgs/populate/src/probe.rs11
-rw-r--r--pkgs/populate/src/sh.rs18
3 files changed, 39 insertions, 21 deletions
diff --git a/pkgs/populate/src/populate.rs b/pkgs/populate/src/populate.rs
index 884ecd9..f8d5c0c 100644
--- a/pkgs/populate/src/populate.rs
+++ b/pkgs/populate/src/populate.rs
@@ -211,14 +211,16 @@ impl Delivery<'_> {
}
/// Transfers source_path, prepared on the deploying machine, to the
- /// target path, with rsync's default configuration.
+ /// target path, with rsync's default configuration, unless the probe
+ /// listed the target path, and it has what rsync would transfer.
fn transfer(&self, source_path: &Path) -> Result<Outcome> {
- let changed = rsync::transfer(
- self.context,
- &Config::default(),
- &source_path.to_string_lossy(),
- self.path,
- )?;
+ let config = Config::default();
+ let listing = self.target.and_then(|target| target.listing.as_ref());
+ let prepared = rsync::prepare(&config, &source_path.to_string_lossy(), listing.is_some())?;
+ if prepared.listing.is_some() && prepared.listing.as_ref() == listing {
+ return Ok(Outcome::changed(false));
+ }
+ let changed = rsync::transfer_prepared(self.context, &config, &prepared, self.path)?;
Ok(Outcome::changed(!changed.is_empty()))
}
}
@@ -356,9 +358,10 @@ fn gathered(
/// What the probe looks for at a source's target path, see probe::probe:
/// the listing of a file source that's a directory, that rsync compares by
-/// size and time, not checksum, the symlink of a symlink source, and the
-/// work tree of a git source with a commit as ref. Not where the flakes
-/// step rewrites a lock file in place, which delivering brings back.
+/// size and time, not checksum, and of a passage source, the symlink of a
+/// symlink source, the .pass_info of a pass source, and the work tree of a
+/// git source with a commit as ref. Not where the flakes step rewrites a
+/// lock file in place, which delivering brings back.
fn probed(_name: &str, source: &Source) -> Option<&'static str> {
if in_place_lock(source).is_some() {
return None;
@@ -368,6 +371,8 @@ fn probed(_name: &str, source: &Source) -> Option<&'static str> {
.is_ok_and(|path| Path::new(path).is_dir() && !file_config(source, path).use_checksum)
.then_some("F"),
"symlink" => Some("L"),
+ "passage" => Some("F"),
+ "pass" => Some("I"),
"git" => (string(&source.settings, "ref").is_ok_and(probe::is_commit)
&& source.settings.get("fetchAlways").and_then(Value::as_bool) != Some(true))
.then_some("G"),
@@ -585,7 +590,11 @@ impl Kind for Pass {
))?;
let info = info.trim_end_matches('\n');
if !info.is_empty() {
- let delivered = d.context.output(sh::PASS_INFO, &[d.path])?;
+ // What the probe read, else a command on the target.
+ let delivered = match d.target.and_then(|probed| probed.info.clone()) {
+ Some(delivered) => delivered,
+ None => d.context.output(sh::PASS_INFO, &[d.path])?,
+ };
if delivered.trim_end_matches('\n') == info {
return Ok(Outcome::changed(false));
}
diff --git a/pkgs/populate/src/probe.rs b/pkgs/populate/src/probe.rs
index 7228cd2..3da117a 100644
--- a/pkgs/populate/src/probe.rs
+++ b/pkgs/populate/src/probe.rs
@@ -1,7 +1,8 @@
//! What's at the target paths of the sources whose delivery may find
//! nothing to do, found out with one command on the target, right after
-//! taking the lock, so their delivery doesn't need any: file sources, see
-//! rsync's Listing, symlink sources, and git sources with a commit as ref.
+//! taking the lock, so their delivery doesn't need any: file and passage
+//! sources, see rsync's Listing, symlink and pass sources, and git sources
+//! with a commit as ref.
use crate::rsync::{self, Listing};
use crate::run::{Context, Result};
@@ -12,10 +13,13 @@ use std::collections::BTreeMap;
/// What the probe found at a source's target path.
#[derive(Debug, Default, PartialEq)]
pub struct Target {
- /// For a file source, its listing, if populate can compare it.
+ /// For a file or passage source, its listing, if populate can compare
+ /// it.
pub listing: Option<Listing>,
/// For a symlink source, the target of the symlink there, if any.
pub link: Option<String>,
+ /// For a pass source, what its .pass_info contains, if anything.
+ pub info: Option<String>,
/// For a git source, the state of the work tree there, if it's one
/// that git_problems finds nothing wrong with.
pub git: Option<Git>,
@@ -125,6 +129,7 @@ fn parse(output: &str) -> BTreeMap<String, Target> {
}
}
"L" => target.link = fields.next().map(str::to_string),
+ "I" => target.info = fields.next().map(str::to_string),
// Dirty until git status says otherwise.
"C" => {
fields.next();
diff --git a/pkgs/populate/src/sh.rs b/pkgs/populate/src/sh.rs
index dc44854..9d2b1d4 100644
--- a/pkgs/populate/src/sh.rs
+++ b/pkgs/populate/src/sh.rs
@@ -347,13 +347,14 @@ fi
/// probe KIND PATH...: prints, for each pair of KIND and PATH, what
/// probe::Target takes from it: P and PATH, then, for KIND F, an entry like
/// listings prints for each thing at and below PATH, for L, if PATH is a
-/// symlink, L and its target, and for G, if PATH is a directory with a .git
-/// directory that git_problems finds nothing wrong with, C, H and HEAD, U and
-/// the origin's URL, D and what git status prints for anything modified,
-/// untracked, or ignored, and, with submodules, M and what git submodule
-/// status prints for them, and S and an exit status, all separated by NULs.
-/// Git runs like the git script runs it, without hooks and file system
-/// monitors, and without writing the index.
+/// symlink, L and its target, for I, I and what PATH/.pass_info contains,
+/// if anything, like pass_info prints it, and for G, if PATH is a directory
+/// with a .git directory that git_problems finds nothing wrong with, C, H
+/// and HEAD, U and the origin's URL, D and what git status prints for
+/// anything modified, untracked, or ignored, and, with submodules, M and
+/// what git submodule status prints for them, and S and an exit status,
+/// all separated by NULs. Git runs like the git script runs it, without
+/// hooks and file system monitors, and without writing the index.
pub fn probe() -> String {
GIT_PROBLEMS.to_string()
+ r#"
@@ -377,6 +378,9 @@ while test $# -gt 1; do
printf 'L\0%s\0' "$(readlink "$path")"
fi
;;
+ I)
+ printf 'I\0%s\0' "$(cat "$path"/.pass_info 2>/dev/null || :)"
+ ;;
G)
if ! test -L "$path" && test -d "$path" &&
! test -L "$path"/.git && test -d "$path"/.git &&
[cgit] Unable to lock slot /tmp/cgit/7c000000.lock: Permission denied (13)