mirror of
https://github.com/restic/rest-server.git
synced 2025-10-19 07:33:21 +00: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:
parent
82816c67e1
commit
2175029c9e
1 changed files with 19 additions and 0 deletions
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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue