From adbb5dbc43399100472c355a7c49ea86e941a843 Mon Sep 17 00:00:00 2001 From: Caj Larsson Date: Sun, 8 May 2022 18:47:27 +0800 Subject: [PATCH] Truncate and unreserve on file replacement --- dataswamp/swamp_service.go | 2 ++ infrastructure/fs/swampfile/repository.go | 1 + 2 files changed, 3 insertions(+) diff --git a/dataswamp/swamp_service.go b/dataswamp/swamp_service.go index a36cad1..6536d41 100644 --- a/dataswamp/swamp_service.go +++ b/dataswamp/swamp_service.go @@ -77,6 +77,8 @@ func (s SwampFileService) SaveFile(ref swampfile.FileReference, src io.Reader, s return err } + ns.Usage = ns.Usage.Add(-f.Size()) + written, err := io.CopyN(f, src, size) if written < size { diff --git a/infrastructure/fs/swampfile/repository.go b/infrastructure/fs/swampfile/repository.go index 173e5a6..c33a991 100644 --- a/infrastructure/fs/swampfile/repository.go +++ b/infrastructure/fs/swampfile/repository.go @@ -98,6 +98,7 @@ func (f Repository) Create(filename string, namespace_ns string) (swampfile.Swam if err != nil { panic(err) } + file.Truncate(0) bfd := FileSystemSwampFileData{filename, stat_info.Size(), stat_info.ModTime(), file}