From cde0e6f6d2eb796d959391191a09811573c6949b Mon Sep 17 00:00:00 2001 From: Ben Pate Date: Sun, 24 Nov 2024 00:52:38 -0700 Subject: [PATCH] Clean up temp file --- service/streamArchive.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/service/streamArchive.go b/service/streamArchive.go index 2f043178..0dfddde8 100644 --- a/service/streamArchive.go +++ b/service/streamArchive.go @@ -111,6 +111,13 @@ func (service *StreamArchive) Create(stream *model.Stream, options StreamArchive return derp.Wrap(err, location, "Error creating ZIP archive") } + // If we fail creating or moving the temp file, then try to delete it. + defer func() { + if err := service.exportCache.Remove(tempFilename); err != nil { + derp.Report(derp.Wrap(err, location, "Error deleting temp file")) + } + }() + // Move the temp file to the permanent location if err := service.exportCache.Rename(tempFilename, filename); err != nil { return derp.Wrap(err, location, "Error moving temp file into place")