]> Cypherpunks.ru repositories - gocheese.git/commitdiff
Sync directories renaming
authorSergey Matveev <stargrave@stargrave.org>
Fri, 6 Dec 2019 13:30:35 +0000 (16:30 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Fri, 6 Dec 2019 13:30:35 +0000 (16:30 +0300)
gocheese.go
tmp.go

index 8a4a6e59da74fe6f35a0e5c2b648992096991a5e..75a7c1caf120a5b83803f6a099bc8625032d64d7 100644 (file)
@@ -202,6 +202,10 @@ 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 {
@@ -426,6 +430,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
diff --git a/tmp.go b/tmp.go
index 9438646907f2b5bce2fd01ad8dd9e7ddd5382558..70d3f1123840718924d05f4817cdabdcf6034aa6 100644 (file)
--- a/tmp.go
+++ b/tmp.go
@@ -31,6 +31,19 @@ func TempFile(dir string) (*os.File, error) {
        return os.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_EXCL, os.FileMode(0666))
 }
 
+func DirSync(dirPath string) error {
+       fd, err := os.Open(dirPath)
+       if err != nil {
+               return err
+       }
+       err = fd.Sync()
+       if err != nil {
+               fd.Close()
+               return err
+       }
+       return fd.Close()
+}
+
 func WriteFileSync(dirPath, filePath string, data []byte) error {
        dst, err := TempFile(dirPath)
        if err != nil {
@@ -47,5 +60,8 @@ func WriteFileSync(dirPath, filePath string, data []byte) error {
                return err
        }
        dst.Close()
-       return os.Rename(dst.Name(), filePath)
+       if err = os.Rename(dst.Name(), filePath); err != nil {
+               return err
+       }
+       return DirSync(dirPath)
 }