X-Git-Url: http://www.git.cypherpunks.ru/?p=gocheese.git;a=blobdiff_plain;f=tmp.go;h=70d3f1123840718924d05f4817cdabdcf6034aa6;hp=9438646907f2b5bce2fd01ad8dd9e7ddd5382558;hb=7463a4bbcd0ace5790125f2d3f01eb48abaca985;hpb=8c1fd82f1cf767c7616e84ebe63b68d7cf033ba2 diff --git a/tmp.go b/tmp.go index 9438646..70d3f11 100644 --- 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) }