From 1face36b81cbe328790ab654fca7d488ffdaf813 Mon Sep 17 00:00:00 2001 From: Adrian Shum Date: Tue, 9 Jul 2024 16:41:42 +0800 Subject: [PATCH] fix(filestorage): sync and attempt delete file on error --- storage/filestorage/filestorage.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/storage/filestorage/filestorage.go b/storage/filestorage/filestorage.go index f7c706390..0500a9c9f 100644 --- a/storage/filestorage/filestorage.go +++ b/storage/filestorage/filestorage.go @@ -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 }