summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick White <git@njw.name>2021-05-31 14:31:42 +0100
committerNick White <git@njw.name>2021-05-31 14:31:42 +0100
commit1ba408a79a585ec1a4ac06bdab19267376bfb676 (patch)
tree4eddf2a4f67abb9d0470f0ac8464d60402450e0b
parentf1dce0812200ca40b58445321e7445ba0a2ef235 (diff)
local: Only create a file once we are sure that it will be writeable
-rw-r--r--local.go10
1 files changed, 5 insertions, 5 deletions
diff --git a/local.go b/local.go
index 44aea76..85a4edc 100644
--- a/local.go
+++ b/local.go
@@ -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
}