X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=gocheese.go;h=2ba14d6616f6a328a98127dd8cf223806ff908ba;hb=a4c518dfd95c8e8b18f822aa90048a0788cc2680;hp=8a4a6e59da74fe6f35a0e5c2b648992096991a5e;hpb=8c1fd82f1cf767c7616e84ebe63b68d7cf033ba2;p=gocheese.git diff --git a/gocheese.go b/gocheese.go index 8a4a6e5..2ba14d6 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 @@ -536,10 +553,10 @@ func goodIntegrity() bool { log.Fatal(err) } if bytes.Compare(hasher.Sum(digest[:0]), data) == 0 { - log.Println(pkgName, "GOOD") + fmt.Println(pkgName, "GOOD") } else { isGood = false - log.Println(pkgName, "BAD") + fmt.Println(pkgName, "BAD") } hasher.Reset() }