From 1cff56a7093ead5a7b427c99532677732633b6db Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Sun, 3 Oct 2021 08:53:03 +0200 Subject: [PATCH] refactor: do not write empty cache list --- src/environment_cache.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/environment_cache.go b/src/environment_cache.go index ac50b228..3e9db87a 100644 --- a/src/environment_cache.go +++ b/src/environment_cache.go @@ -40,7 +40,11 @@ func (fc *fileCache) init(cachePath string) { } func (fc *fileCache) close() { - if dump, err := json.MarshalIndent(fc.cache.list(), "", " "); err == nil { + cache := fc.cache.list() + if len(cache) == 0 { + return + } + if dump, err := json.MarshalIndent(cache, "", " "); err == nil { _ = ioutil.WriteFile(fc.cachePath+fileName, dump, 0644) } }