refactor: do not write empty cache list

This commit is contained in:
Jan De Dobbeleer 2021-10-03 08:53:03 +02:00 committed by Jan De Dobbeleer
parent a118e178b5
commit 1cff56a709

View file

@ -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)
}
}