aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/populate/src/populate.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-12-01 00:26:36 +0000
committertv <tv@krebsco.de>2026-12-01 00:26:36 +0000
commit5df6e41e05b9449a964467bc11a9d7fce2d802ec (patch)
treede72c779f03f7cb55ce083d527fc479245d0c8ef /pkgs/populate/src/populate.rs
parent85afc649ffeea7c92027f57e0a1bdec27d9bc8c9 (diff)
populate: skip symlink and git sources with nothing to do
Each command on a remote target costs about three round trips, so the bench's 30 symlink and 20 git sources took about 4.5 of a no-op run's 7.2 s with 30 ms to the target, with one command each. The command after taking the lock that lists file sources, now the probe (probe.rs), also finds out what's at the target paths of symlink sources, the symlink, if any, and of git sources with a commit as ref and without fetchAlways: if git_problems finds nothing wrong with the work tree, which keeps guarding every Git command, its HEAD, its origin's URL, and what git status --ignored and git submodule status print. A symlink source whose symlink points to the target already runs nothing. So does a git source whose work tree has the commit checked out, the source's URL, nothing modified, untracked, or ignored, and its submodules at their commits; the flakes step takes it for checked, as after the git script. Not where the flakes step rewrites a lock file in place. The scenario symlink-git-skip checks that an unchanged symlink stays the same file, which ln would replace, and that a symlink pointing elsewhere, a modified file, an untracked one, and another commit make them deliver again.
Diffstat (limited to 'pkgs/populate/src/populate.rs')
-rw-r--r--pkgs/populate/src/populate.rs80
1 files changed, 40 insertions, 40 deletions
diff --git a/pkgs/populate/src/populate.rs b/pkgs/populate/src/populate.rs
index 668053a..cab1a91 100644
--- a/pkgs/populate/src/populate.rs
+++ b/pkgs/populate/src/populate.rs
@@ -2,13 +2,13 @@
use crate::flake;
use crate::flake_input;
+use crate::probe;
use crate::record;
use crate::rsync::{self, Config};
use crate::run::{self, Context, Failure, Result};
use crate::sh;
use crate::spec::{Source, Spec};
use serde_json::{json, Map, Value};
-use std::collections::BTreeMap;
use std::fs;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
@@ -57,7 +57,7 @@ pub fn populate(context: &Context, spec: &Spec) -> Result<()> {
if spec.backup {
context.run(&sh::backup(), &[dir])?;
}
- let listings = target_listings(context, spec)?;
+ let probed = probe::probe(context, spec, probed)?;
for (name, source) in &spec.source {
let path = format!("{dir}/{name}");
eprintln!("populating '{}'...", context.name(&path));
@@ -78,7 +78,7 @@ pub fn populate(context: &Context, spec: &Spec) -> Result<()> {
source,
path: &path,
workdir,
- listing: listings.get(name).and_then(Option::as_ref),
+ target: probed.get(name),
};
context.note(json!({ "begin": name }));
let outcome = kind.deliver(&delivery)?;
@@ -191,9 +191,9 @@ struct Delivery<'a> {
path: &'a str,
/// Where to prepare files on the deploying machine.
workdir: PathBuf,
- /// The listing of the target path, for a file source whose transfer may
- /// find nothing to do, see target_listings.
- listing: Option<&'a rsync::Listing>,
+ /// What the probe found at the target path, for a source whose delivery
+ /// may find nothing to do, see probed.
+ target: Option<&'a probe::Target>,
}
impl Delivery<'_> {
@@ -302,39 +302,25 @@ fn file_config(source: &Source, source_path: &str) -> Config {
}
}
-/// The listings of the target paths of the file sources whose transfer may
-/// find nothing to do, by name, see File::deliver: of directories, that
-/// rsync compares by size and time, not checksum, and that the flakes step
-/// doesn't rewrite a lock file in. One command on the target lists them
-/// all.
-fn target_listings(
- context: &Context,
- spec: &Spec,
-) -> Result<BTreeMap<String, Option<rsync::Listing>>> {
- let dir = &spec.target.path;
- let names: Vec<&String> = spec
- .source
- .iter()
- .filter(|(_, source)| {
- source.kind == "file"
- && in_place_lock(source).is_none()
- && string(&source.settings, "path").is_ok_and(|path| {
- Path::new(path).is_dir() && !file_config(source, path).use_checksum
- })
- })
- .map(|(name, _)| name)
- .collect();
- if names.is_empty() {
- return Ok(BTreeMap::new());
+/// 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.
+fn probed(_name: &str, source: &Source) -> Option<&'static str> {
+ if in_place_lock(source).is_some() {
+ return None;
+ }
+ match source.kind.as_str() {
+ "file" => string(&source.settings, "path")
+ .is_ok_and(|path| Path::new(path).is_dir() && !file_config(source, path).use_checksum)
+ .then_some("F"),
+ "symlink" => Some("L"),
+ "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"),
+ _ => None,
}
- let paths: Vec<String> = names.iter().map(|name| format!("{dir}/{name}")).collect();
- let args: Vec<&str> = paths.iter().map(String::as_str).collect();
- let mut found = rsync::found(&context.output(sh::LISTINGS, &args)?);
- Ok(names
- .into_iter()
- .zip(&paths)
- .map(|(name, path)| (name.clone(), found.remove(path).flatten()))
- .collect())
}
impl Kind for File {
@@ -343,8 +329,9 @@ impl Kind for File {
let config = file_config(d.source, source_path);
// Nothing to do if what rsync would transfer and what's at the
// target path are the same as far as rsync's quick check goes.
- let prepared = rsync::prepare(&config, source_path, d.listing.is_some())?;
- let changed = if prepared.listing.is_some() && prepared.listing.as_ref() == d.listing {
+ let listing = d.target.and_then(|target| target.listing.as_ref());
+ let prepared = rsync::prepare(&config, source_path, listing.is_some())?;
+ let changed = if prepared.listing.is_some() && prepared.listing.as_ref() == listing {
Vec::new()
} else {
rsync::transfer_prepared(d.context, &config, &prepared, d.path)?
@@ -447,6 +434,15 @@ impl Kind for Git {
.into_iter()
.flatten()
.filter_map(Value::as_str);
+ // Nothing to do if the work tree there, which git_problems found
+ // nothing wrong with, has the commit checked out, and nothing that
+ // git reset, git clean, or updating submodules would change.
+ if let Some(git) = d.target.and_then(|probed| probed.git.as_ref()) {
+ if git.unchanged(d.string("url")?, d.string("ref")?) {
+ d.context.git_checked(d.path);
+ return Ok(Outcome::changed(false).with("commit", git.head.as_str()));
+ }
+ }
let name = d.context.name(d.path);
let mut args = vec![
d.path,
@@ -542,6 +538,10 @@ struct Symlink;
impl Kind for Symlink {
fn deliver(&self, d: &Delivery) -> Result<Outcome> {
let target = d.string("target")?;
+ // Nothing to do if the symlink there points to target already.
+ if d.target.and_then(|probed| probed.link.as_deref()) == Some(target) {
+ return Ok(Outcome::changed(false).with("target", target));
+ }
let output = d.context.output(&sh::symlink(), &[d.path, target])?;
Ok(Outcome::changed(output.contains("changed")).with("target", target))
}
[cgit] Unable to lock slot /tmp/cgit/df100000.lock: Permission denied (13)