mirror of
https://github.com/restic/rest-server.git
synced 2026-09-25 13:31:31 -07: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:
@@ -627,9 +627,28 @@ func (h *Handler) saveBlob(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
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))
|
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.
|
// deleteBlob deletes a blob from the repository.
|
||||||
func (h *Handler) deleteBlob(w http.ResponseWriter, r *http.Request) {
|
func (h *Handler) deleteBlob(w http.ResponseWriter, r *http.Request) {
|
||||||
if h.opt.Debug {
|
if h.opt.Debug {
|
||||||
|
|||||||
Reference in New Issue
Block a user