]> Cypherpunks.ru repositories - gocheese.git/blobdiff - tmp.go
Sync directories renaming
[gocheese.git] / tmp.go
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)
 }