fix: fail a dump when its first pipeline stage dies
This commit is contained in:
@@ -180,6 +180,13 @@ fn read_header(path: &Path) -> Result<Vec<u8>> {
|
|||||||
Ok(header)
|
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> {
|
fn piped(db: &Database, script: &str, input: &Path) -> Result<std::process::Command> {
|
||||||
let file = File::open(input).with_context(|| format!("opening {}", input.display()))?;
|
let file = File::open(input).with_context(|| format!("opening {}", input.display()))?;
|
||||||
let mut command = CommandBuilder::docker()
|
let mut command = CommandBuilder::docker()
|
||||||
@@ -294,7 +301,10 @@ pub fn import(file: &Path) -> Result<()> {
|
|||||||
|
|
||||||
let kind = Kind::of(&out.stdout);
|
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")
|
.args("exec")
|
||||||
.arg(&db.container)
|
.arg(&db.container)
|
||||||
.args("sh -c")
|
.args("sh -c")
|
||||||
.arg(format!("{} | gzip", dump_command(&db, format)))
|
.arg(pipefail(&format!("{} | gzip", dump_command(&db, format))))
|
||||||
.exec_redirect_stdout(stdout)
|
.exec_redirect_stdout(stdout)
|
||||||
} else {
|
} else {
|
||||||
let dumping = match format.flag() {
|
let dumping = match format.flag() {
|
||||||
|
|||||||
Reference in New Issue
Block a user