diff options
Diffstat (limited to 'pkgs/populate/src/populate.rs')
| -rw-r--r-- | pkgs/populate/src/populate.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/pkgs/populate/src/populate.rs b/pkgs/populate/src/populate.rs index cab1a91..6c4fd42 100644 --- a/pkgs/populate/src/populate.rs +++ b/pkgs/populate/src/populate.rs @@ -10,6 +10,7 @@ use crate::sh; use crate::spec::{Source, Spec}; use serde_json::{json, Map, Value}; use std::fs; +use std::os::unix::fs::DirBuilderExt; use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; @@ -384,6 +385,9 @@ struct Pipe; impl Kind for Pipe { fn deliver(&self, d: &Delivery) -> Result<Outcome> { + if d.source.settings.get("directory").and_then(Value::as_bool) == Some(true) { + return deliver_directory(d); + } let out = d.workdir.join("out"); let file = fs::File::create(&out) .map_err(|e| Failure::Message(format!("error: can't create {}: {e}", out.display())))?; @@ -408,6 +412,43 @@ impl Kind for Pipe { } } +/// A pipe source's directory: the command fills an empty directory, which +/// it gets as $1, mode 0700 in populate's temporary directory, so nothing +/// on the way is anyone else's to read, and what it makes there goes to +/// the target path, with the modes it has, and the fixed time of pipe's +/// output, compared by checksum. +fn deliver_directory(d: &Delivery) -> Result<Outcome> { + let out = d.workdir.join("out"); + fs::DirBuilder::new() + .mode(0o700) + .create(&out) + .map_err(|e| Failure::Message(format!("error: can't create {}: {e}", out.display())))?; + let out = out.to_string_lossy(); + // Through a shell, which runs a command without #! as a script. + run::status(&mut run::local_shell( + "\"$1\" \"$2\"\n", + &[d.string("command")?, &out], + &d.workdir, + ))?; + // The fixed time of pipe's output, so the same contents don't change + // anything at the target path, and only checksums tell them apart. + run::status(Command::new("find").arg(out.as_ref()).args([ + "-exec", + "touch", + "-h", + "-t", + "300001010000", + "{}", + "+", + ]))?; + let config = Config { + use_checksum: true, + ..Config::default() + }; + let changed = rsync::transfer(d.context, &config, &out, d.path)?; + Ok(Outcome::changed(!changed.is_empty())) +} + /// A flake, or an input of one, delivered as a link into the store. struct Flake; |
