X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=refresh.go;h=ea3af19c049d4738273a63f9189267577914e5f7;hb=6f8bc330934aacc401c00d9c3d0cf8eeceb296b1;hp=fcee245b93d15fce58322dcf1c16c72d8770cd1c;hpb=371b9da450b741c6dc50cf5427fcbdec4335d0fc;p=gocheese.git diff --git a/refresh.go b/refresh.go index fcee245..ea3af19 100644 --- a/refresh.go +++ b/refresh.go @@ -1,6 +1,6 @@ /* GoCheese -- Python private package repository and caching proxy -Copyright (C) 2019-2021 Sergey Matveev +Copyright (C) 2019-2022 Sergey Matveev This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -28,7 +28,6 @@ import ( "errors" "hash" "io" - "io/ioutil" "log" "net/http" "net/url" @@ -115,7 +114,13 @@ func refreshDir( http.Error(w, "PyPI has non 200 status code", http.StatusBadGateway) return false } - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) + if err != nil { + resp.Body.Close() + log.Println("error", r.RemoteAddr, "refresh-json", pkgName, err) + http.Error(w, "can not read body", http.StatusBadGateway) + return false + } resp.Body.Close() var buf bytes.Buffer var description string @@ -234,7 +239,7 @@ func refreshDir( return false } path := filepath.Join(dirPath, MDFile) - existing, err := ioutil.ReadFile(path) + existing, err := os.ReadFile(path) if err != nil || bytes.Compare(existing, buf.Bytes()) != 0 { if err = WriteFileSync(dirPath, path, buf.Bytes(), now); err != nil { log.Println("error", r.RemoteAddr, "refresh-json", path, err) @@ -278,7 +283,7 @@ func refreshDir( http.Error(w, "PyPI has non 200 status code", http.StatusBadGateway) return false } - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) resp.Body.Close() if err != nil { log.Println("error", r.RemoteAddr, "refresh", pkgName, err) @@ -428,7 +433,7 @@ func refreshDir( http.Error(w, "digest mismatch", http.StatusBadGateway) return false } - if digestStored, err := ioutil.ReadFile(path + "." + hashAlgo); err == nil && + if digestStored, err := os.ReadFile(path + "." + hashAlgo); err == nil && bytes.Compare(digest, digestStored) != 0 { err = errors.New("stored digest mismatch") log.Println("error", r.RemoteAddr, "pypi", filename, err) @@ -517,9 +522,6 @@ func refreshDir( } if filename == filenameGet || gpgUpdate { - if _, err = os.Stat(path); err != nil { - goto GPGSigSkip - } resp, err := c.Do(agentedReq(uri + GPGSigExt)) if err != nil { goto GPGSigSkip @@ -528,7 +530,7 @@ func refreshDir( resp.Body.Close() goto GPGSigSkip } - sig, err := ioutil.ReadAll(resp.Body) + sig, err := io.ReadAll(resp.Body) resp.Body.Close() if err != nil { goto GPGSigSkip