mirror of
https://github.com/restic/rest-server.git
synced 2025-12-06 17:15:45 -08:00
Sync directory to disk after upload
After a file was uploaded, also sync its containing directory to disk to make sure that also the directory entry is persisted after a system crash.
This commit is contained in:
19
repo/repo.go
19
repo/repo.go
@@ -627,9 +627,28 @@ func (h *Handler) saveBlob(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := syncDir(filepath.Dir(path)); err != nil {
|
||||
// Don't call os.Remove(path) as this is prone to race conditions with parallel upload retries
|
||||
h.internalServerError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
h.sendMetric(objectType, BlobWrite, uint64(written))
|
||||
}
|
||||
|
||||
func syncDir(dirname string) error {
|
||||
dir, err := os.Open(dirname)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = dir.Sync()
|
||||
if err != nil {
|
||||
_ = dir.Close()
|
||||
return err
|
||||
}
|
||||
return dir.Close()
|
||||
}
|
||||
|
||||
// deleteBlob deletes a blob from the repository.
|
||||
func (h *Handler) deleteBlob(w http.ResponseWriter, r *http.Request) {
|
||||
if h.opt.Debug {
|
||||
|
||||
Reference in New Issue
Block a user