X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;ds=sidebyside;f=gocheese.go;h=5ecd959bc61e6f1a5881f8dc0d6b8c6b97b43de6;hb=5d0340e435f90599a8072ad8cd67ef8ef4be116a;hp=8a4a6e59da74fe6f35a0e5c2b648992096991a5e;hpb=8c1fd82f1cf767c7616e84ebe63b68d7cf033ba2;p=gocheese.git diff --git a/gocheese.go b/gocheese.go index 8a4a6e5..5ecd959 100644 --- a/gocheese.go +++ b/gocheese.go @@ -202,22 +202,35 @@ func refreshDir( http.Error(w, err.Error(), http.StatusInternalServerError) return false } + if err = DirSync(dirPath); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return false + } } if filename == filenameGet || gpgUpdate { - if _, err = os.Stat(path); err == nil { - if resp, err := http.Get(pkgURL.String() + GPGSigExt); err == nil { - sig, err := ioutil.ReadAll(resp.Body) - resp.Body.Close() - if err == nil { - if err = WriteFileSync(dirPath, path+GPGSigExt, sig); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return false - } - log.Println(r.RemoteAddr, "pypi downloaded signature", filename) - } - } + if _, err = os.Stat(path); err != nil { + goto GPGSigSkip } + resp, err := http.Get(pkgURL.String() + GPGSigExt) + if err != nil { + goto GPGSigSkip + } + if resp.StatusCode != http.StatusOK { + resp.Body.Close() + goto GPGSigSkip + } + sig, err := ioutil.ReadAll(resp.Body) + resp.Body.Close() + if err != nil { + goto GPGSigSkip + } + if err = WriteFileSync(dirPath, path+GPGSigExt, sig); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return false + } + log.Println(r.RemoteAddr, "pypi downloaded signature", filename) } + GPGSigSkip: path = path + SHA256Ext _, err = os.Stat(path) if err == nil { @@ -426,6 +439,10 @@ func serveUpload(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), http.StatusInternalServerError) return } + if err = DirSync(dirPath); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } if err = WriteFileSync(dirPath, path+SHA256Ext, digest); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return