summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
7823947)
Previously the file was first truncated or created and then written to.
Although "convert" is not designed to be used for deployment, it is a
unexpected behavior.
return fmt.Errorf("unsupported file type %v", t)
}
return fmt.Errorf("unsupported file type %v", t)
}
- // We must create the file first or deployFile() will abort
- f, err := os.Create(dstPath)
+ dstDir := filepath.Dir(dstPath)
+ dstName := filepath.Base(dstPath)
+
+ // We must create the file first or deployFile() will abort; this is
+ // ugly because deployFile() already performs an atomic replacement
+ // but the simplest solution with the least duplicate code
+ f, err := ioutil.TempFile(dstDir, "tmp-"+dstName+"-")
if err != nil {
return err
}
if err != nil {
return err
}
+ tmpPath := f.Name()
+ defer os.Remove(tmpPath)
f.Close()
err = deployFile(&File{
Type: t,
Url: srcPath,
f.Close()
err = deployFile(&File{
Type: t,
Url: srcPath,
body: x.Bytes(),
})
if err != nil {
return err
}
body: x.Bytes(),
})
if err != nil {
return err
}
+
+ return os.Rename(tmpPath, dstPath)