Skip to content

Commit

Permalink
fix(filestorage): sync and attempt delete file on error (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
cshum authored Jul 9, 2024
1 parent 716f298 commit ef34a5f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions storage/filestorage/filestorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,16 @@ func (s *FileStorage) Put(_ context.Context, image string, blob *imagor.Blob) (e
}
defer func() {
_ = w.Close()
if err != nil {
_ = os.Remove(w.Name())
}
}()
if _, err = io.Copy(w, reader); err != nil {
return
}
if err = w.Sync(); err != nil {
return
}
return
}

Expand Down

0 comments on commit ef34a5f

Please sign in to comment.