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 {
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
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 {
return err
}
dst.Close()
- return os.Rename(dst.Name(), filePath)
+ if err = os.Rename(dst.Name(), filePath); err != nil {
+ return err
+ }
+ return DirSync(dirPath)
}