From f4a0ee8e229eaeed0b03bd0ec23a3f639f0097d8 Mon Sep 17 00:00:00 2001 From: Radhi Fadlillah Date: Sun, 9 Jun 2019 16:59:03 +0700 Subject: [PATCH] Before updating, remove the old archive --- internal/cmd/update.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/internal/cmd/update.go b/internal/cmd/update.go index 1dff291f..69628489 100644 --- a/internal/cmd/update.go +++ b/internal/cmd/update.go @@ -6,6 +6,7 @@ import ( "io" "net/http" nurl "net/url" + "os" fp "path/filepath" "sort" "strings" @@ -161,12 +162,14 @@ func updateHandler(cmd *cobra.Command, args []string) { } defer resp.Body.Close() - // Save as archive + // Save as archive, make sure to delete the old one first + archivePath := fp.Join(DataDir, "archive", fmt.Sprintf("%d", book.ID)) + os.Remove(archivePath) + buffer := bytes.NewBuffer(nil) tee := io.TeeReader(resp.Body, buffer) contentType := resp.Header.Get("Content-Type") - archivePath := fp.Join(DataDir, "archive", fmt.Sprintf("%d", book.ID)) err = warc.FromReader(tee, book.URL, contentType, archivePath) if err != nil { chProblem <- book.ID