From d2e59a9dbd1d1fde84056aa52c4830f7bea03f64 Mon Sep 17 00:00:00 2001 From: Big Duckie Date: Tue, 31 Dec 2024 03:28:02 -0700 Subject: [PATCH] Fixed issue where zips wouldn't be closed after trying to read comicinfo.xml. --- app/routes/routes.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/app/routes/routes.go b/app/routes/routes.go index 44ba0d2..6935440 100644 --- a/app/routes/routes.go +++ b/app/routes/routes.go @@ -71,18 +71,19 @@ func Index(w http.ResponseWriter, r *http.Request) { zf, err := zip.OpenReader(path) if err != nil { return nil - } else { - for i := range zf.File { - if strings.ToLower(zf.File[i].Name) == "comicinfo.xml" { - cif, err := zf.File[i].Open() - if err != nil { - return err - } - cib, _ := io.ReadAll(cif) - _ = cif.Close() - _ = xml.Unmarshal(cib, &ComicInfo) - c.Set(path, ComicInfo, cache.NoExpiration) + } + + defer zf.Close() + for i := range zf.File { + if strings.ToLower(zf.File[i].Name) == "comicinfo.xml" { + cif, err := zf.File[i].Open() + if err != nil { + return nil } + cib, _ := io.ReadAll(cif) + _ = cif.Close() + _ = xml.Unmarshal(cib, &ComicInfo) + c.Set(path, ComicInfo, cache.NoExpiration) } } }