diff options
author | Nick White <git@njw.name> | 2021-05-31 14:31:42 +0100 |
---|---|---|
committer | Nick White <git@njw.name> | 2021-05-31 14:31:42 +0100 |
commit | 1ba408a79a585ec1a4ac06bdab19267376bfb676 (patch) | |
tree | 4eddf2a4f67abb9d0470f0ac8464d60402450e0b /local.go | |
parent | f1dce0812200ca40b58445321e7445ba0a2ef235 (diff) |
local: Only create a file once we are sure that it will be writeable
Diffstat (limited to 'local.go')
-rw-r--r-- | local.go | 10 |
1 files changed, 5 insertions, 5 deletions
@@ -238,17 +238,17 @@ func (a *LocalConn) Upload(bucket string, key string, path string) error { if err != nil && !os.IsExist(err) { return fmt.Errorf("Error creating temporary directory: %v", err) } - f, err := os.Create(filepath.Join(a.TempDir, bucket, key)) - if err != nil { - return err - } - defer f.Close() fin, err := os.Open(path) if err != nil { return err } defer fin.Close() + f, err := os.Create(filepath.Join(a.TempDir, bucket, key)) + if err != nil { + return err + } + defer f.Close() _, err = io.Copy(f, fin) return err } |