mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
pkg/atomicwriter: New(): prevent creating temp-file on errors
The temp-file was created before trying to make the given filename an absolute path. Reverse the order of code so that we don't create a temp-file if an error happens. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -11,12 +11,12 @@ import (
|
||||
// destination path. Writing and closing concurrently is not allowed.
|
||||
// NOTE: umask is not considered for the file's permissions.
|
||||
func New(filename string, perm os.FileMode) (io.WriteCloser, error) {
|
||||
f, err := os.CreateTemp(filepath.Dir(filename), ".tmp-"+filepath.Base(filename))
|
||||
abspath, err := filepath.Abs(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
abspath, err := filepath.Abs(filename)
|
||||
f, err := os.CreateTemp(filepath.Dir(filename), ".tmp-"+filepath.Base(filename))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user