]> Cypherpunks.ru repositories - gocheese.git/blobdiff - gocheese.go
Check for 404 error of .asc downloads
[gocheese.git] / gocheese.go
index 8a4a6e59da74fe6f35a0e5c2b648992096991a5e..5ecd959bc61e6f1a5881f8dc0d6b8c6b97b43de6 100644 (file)
@@ -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