Skip to content

Commit 985d205

Browse files
jlebonopenshift-merge-robot
authored andcommitted
kola/cluster: upload files to temporary path and rename
As good practice, upload to a separate file first before renaming it to its final location. That way there's no chance of the file sticking around in its official spot even if we fail. But also, other services that are watching the path won't get a partially written file. Prep for next patch which also adds labeling to that.
1 parent 2f9573c commit 985d205

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

mantle/kola/cluster/cluster.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/coreos/mantle/harness"
2525
"github.com/coreos/mantle/platform"
2626
"github.com/coreos/pkg/capnslog"
27+
"github.com/pkg/errors"
2728
)
2829

2930
var (
@@ -103,9 +104,16 @@ func DropFile(machines []platform.Machine, localPath string) error {
103104
if _, err := in.Seek(0, 0); err != nil {
104105
return err
105106
}
106-
if err := platform.InstallFile(in, m, filepath.Base(localPath)); err != nil {
107+
// write to a separate path first, then rename to its final location so
108+
// that anything watching the path can only get a complete file
109+
base := filepath.Base(localPath)
110+
partial := base + ".partial"
111+
if err := platform.InstallFile(in, m, partial); err != nil {
107112
return err
108113
}
114+
if out, stderr, err := m.SSH(fmt.Sprintf("mv %[1]s.partial %[1]s", base)); err != nil {
115+
return errors.Wrapf(err, "running mv %[1]s.partial %[1]s: %s: %s", base, out, stderr)
116+
}
109117
}
110118
return nil
111119
}

0 commit comments

Comments
 (0)