From 93f416403ecc1e73178ed8bef10213a2c50d5ce1 Mon Sep 17 00:00:00 2001 From: BroodjeAap Date: Tue, 7 Jul 2020 18:38:20 +0000 Subject: [PATCH] more stuff to Stream --- stream.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/stream.go b/stream.go index 9a1cc57..588d679 100755 --- a/stream.go +++ b/stream.go @@ -58,12 +58,19 @@ func (s Stream) SaveStreamInstant(URL string, img []byte) { } if swap { - previousStreamInstantPath := filepath.Join(streamStoreDir, "previous.jpg") - nextStreamInstantPath := currentStreamInstantPath - currentStreamInstantPath = filepath.Join(streamStoreDir, "current.jpg") + s.SwapInstants(s.GetPreviousInstantPath(), s.GetCurrentInstantPath(), s.GetNextInstantPath()) + } +} - err = os.Rename(currentStreamInstantPath, previousStreamInstantPath) - err = os.Rename(nextStreamInstantPath, currentStreamInstantPath) +// SwapInstants swaps the file location, first current -> previous and then next -> current +func (s Stream) SwapInstants(previous string, current string, next string) { + err := os.Rename(current, previous) + if err != nil { + log.Fatal("Couldn't copy current image instant to previous image instant") + } + err = os.Rename(next, current) + if err != nil { + log.Fatal("Couldn't copy next image instant to current image instant") } }