Abort the seed and probe scripts on the first failed command
Guard the staged size as a string so an unmeasurable file fails closed.
This commit is contained in:
@@ -83,14 +83,18 @@ const seedTempSuffix = ".seed-tmp"
|
||||
// installs it in that order. Doing all of it in one exec keeps an interrupted
|
||||
// seed from leaving the PVC with no zone data, which the next reconcile would
|
||||
// read as a fresh install and reseed at serial 1; the rename means a torn write
|
||||
// is never visible at path.
|
||||
// is never visible at path. shellScript aborts the run at the first failure, so
|
||||
// no step can install the skeleton over data an earlier step failed to preserve.
|
||||
func seedScript(path string, plan SeedPlan, size int) string {
|
||||
q, tmp := shellQuote(path), shellQuote(path+seedTempSuffix)
|
||||
cmds := []string{
|
||||
fmt.Sprintf("mkdir -p \"$(dirname %s)\"", q),
|
||||
fmt.Sprintf("cat > %s", tmp),
|
||||
// A stdin stream cut mid-transfer gives cat a short file and exit 0.
|
||||
fmt.Sprintf("if [ \"$(wc -c < %s | tr -d ' \\n')\" -ne %d ]; then rm -f %s; exit 1; fi", tmp, size, tmp),
|
||||
fmt.Sprintf("n=$(wc -c < %s | tr -d ' \\n')", tmp),
|
||||
// Compared as strings: an unmeasurable size is empty, not a number, and
|
||||
// a numeric test would exit 2 there and be swallowed by the if.
|
||||
fmt.Sprintf("if [ \"$n\" != '%d' ]; then rm -f %s; exit 1; fi", size, tmp),
|
||||
}
|
||||
if plan.QuarantineZoneFile {
|
||||
cmds = append(cmds, moveAside(path, plan.QuarantineSuffix))
|
||||
@@ -98,7 +102,7 @@ func seedScript(path string, plan SeedPlan, size int) string {
|
||||
if plan.QuarantineJournal {
|
||||
cmds = append(cmds, moveAside(JournalPath(path), plan.QuarantineSuffix))
|
||||
}
|
||||
return strings.Join(append(cmds, fmt.Sprintf("mv -- %s %s", tmp, q)), "\n")
|
||||
return shellScript(append(cmds, fmt.Sprintf("mv -- %s %s", tmp, q))...)
|
||||
}
|
||||
|
||||
// AddCatalogMember registers a member zone in a catalog zone by adding the
|
||||
|
||||
Reference in New Issue
Block a user