aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/populate
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/populate')
-rw-r--r--pkgs/populate/src/run.rs14
-rw-r--r--pkgs/populate/src/sh.rs8
-rw-r--r--pkgs/populate/tests/scenarios.nix3
3 files changed, 21 insertions, 4 deletions
diff --git a/pkgs/populate/src/run.rs b/pkgs/populate/src/run.rs
index bdff78f..9ef60f1 100644
--- a/pkgs/populate/src/run.rs
+++ b/pkgs/populate/src/run.rs
@@ -387,10 +387,20 @@ impl Context {
}
/// Releases the lock: the input of the command holding it ending ends
- /// the command.
+ /// the command. Before, the command gets the journal's entries that no
+ /// command took to the target yet, e.g. of a run that failed, which it
+ /// appends to the journal.
pub fn unlock(&self) {
if let Some((mut child, _)) = self.lock.borrow_mut().take() {
- drop(child.stdin.take());
+ if let Some(mut stdin) = child.stdin.take() {
+ let (entries, flushed) = &mut *self.entries.borrow_mut();
+ let lines: String = entries[*flushed..]
+ .iter()
+ .map(|entry| format!("{entry}\n"))
+ .collect();
+ *flushed = entries.len();
+ let _ = stdin.write_all(lines.as_bytes());
+ }
let _ = child.wait();
}
}
diff --git a/pkgs/populate/src/sh.rs b/pkgs/populate/src/sh.rs
index 0c200ce..aabf328 100644
--- a/pkgs/populate/src/sh.rs
+++ b/pkgs/populate/src/sh.rs
@@ -190,7 +190,9 @@ fi
/// finish, appends ENTRY to it, prints record and what's in
/// SENTINEL/run.json, the last run's record, if any, and prints locked.
/// Then it keeps the lock until its standard input ends, which consumers
-/// of the target directory can wait for by taking a shared lock. NAME is
+/// of the target directory can wait for by taking a shared lock, and
+/// appends the lines of its input to the journal: the entries no other
+/// command took to the target, e.g. of a run that failed. NAME is
/// the sentinel's name in messages. Writing to a symlink in place of the
/// lock or the journal would write to what it points to, so it refuses
/// those.
@@ -217,7 +219,9 @@ if test -f "$sentinel"/run.json; then
cat "$sentinel"/run.json
fi
echo locked
-exec cat >/dev/null
+while IFS= read -r line; do
+ printf '%s\n' "$line" >> "$sentinel"/journal
+done
"#;
/// record SENTINEL RECORD: writes RECORD to SENTINEL/run.json, replacing
diff --git a/pkgs/populate/tests/scenarios.nix b/pkgs/populate/tests/scenarios.nix
index 0f1051c..f69217b 100644
--- a/pkgs/populate/tests/scenarios.nix
+++ b/pkgs/populate/tests/scenarios.nix
@@ -908,6 +908,9 @@ in
check = ''
cmp "$T"/.populate/run.json "$T".record || fail "record changed"
test -e "$T"/.populate/journal || fail "journal missing"
+ # Also the entry no command after it took to the target.
+ grep -qxF '{"begin":"y"}' "$T"/.populate/journal ||
+ fail "y's begin missing from the journal"
'';
}
{
[cgit] Unable to lock slot /tmp/cgit/8a300000.lock: Permission denied (13)