fix: fail a dump when its first pipeline stage dies

This commit is contained in:
2026-09-08 10:23:42 +00:00
parent 432fa12c53
commit e1817a6824

View File

@@ -180,6 +180,13 @@ fn read_header(path: &Path) -> Result<Vec<u8>> {
Ok(header)
}
// a pipeline reports the last stage's status by default, so a first stage that
// dies mid-stream looks like success; not for pipelines that close the pipe
// early on purpose, where SIGPIPE would then read as failure
fn pipefail(script: &str) -> String {
format!("set -o pipefail; {script}")
}
fn piped(db: &Database, script: &str, input: &Path) -> Result<std::process::Command> {
let file = File::open(input).with_context(|| format!("opening {}", input.display()))?;
let mut command = CommandBuilder::docker()
@@ -294,7 +301,10 @@ pub fn import(file: &Path) -> Result<()> {
let kind = Kind::of(&out.stdout);
(kind, Some(format!("gunzip -c | {}", db.restore_with(kind))))
(
kind,
Some(pipefail(&format!("gunzip -c | {}", db.restore_with(kind)))),
)
}
};
@@ -387,7 +397,7 @@ pub fn dump(file: &PathBuf, format: Format, gzip: bool) -> Result<()> {
.args("exec")
.arg(&db.container)
.args("sh -c")
.arg(format!("{} | gzip", dump_command(&db, format)))
.arg(pipefail(&format!("{} | gzip", dump_command(&db, format))))
.exec_redirect_stdout(stdout)
} else {
let dumping = match format.flag() {