summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick White <git@njw.name>2021-05-19 22:23:41 +0100
committerNick White <git@njw.name>2021-05-19 22:23:41 +0100
commit176aa232973e534a710ce50ab0b3b89e6185fe04 (patch)
treec6c271e4f0935a4c9fb589c92f621c022583126b
parente1a9b682d3a4b4188399c6fd82357d85c92b51aa (diff)
Local download now tries to open the source file before creating a destination file, so if it fails an empty file isnt left behind
-rw-r--r--local.go9
1 files changed, 5 insertions, 4 deletions
diff --git a/local.go b/local.go
index 816b44b..44aea76 100644
--- a/local.go
+++ b/local.go
@@ -215,17 +215,18 @@ func (a *LocalConn) DelFromQueue(url string, handle string) error {
// Download just copies the file from TempDir/bucket/key to path
func (a *LocalConn) Download(bucket string, key string, path string) error {
- f, err := os.Create(path)
+ fin, err := os.Open(filepath.Join(a.TempDir, bucket, key))
if err != nil {
return err
}
- defer f.Close()
+ defer fin.Close()
- fin, err := os.Open(filepath.Join(a.TempDir, bucket, key))
+ f, err := os.Create(path)
if err != nil {
return err
}
- defer fin.Close()
+ defer f.Close()
+
_, err = io.Copy(f, fin)
return err
}