diff options
author | Nick White <git@njw.name> | 2021-05-19 22:23:41 +0100 |
---|---|---|
committer | Nick White <git@njw.name> | 2021-05-19 22:23:41 +0100 |
commit | 176aa232973e534a710ce50ab0b3b89e6185fe04 (patch) | |
tree | c6c271e4f0935a4c9fb589c92f621c022583126b | |
parent | e1a9b682d3a4b4188399c6fd82357d85c92b51aa (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.go | 9 |
1 files changed, 5 insertions, 4 deletions
@@ -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 } |