mirror of
https://github.com/restic/rest-server.git
synced 2025-10-19 15:43:21 +00:00
Merge pull request #231 from MichaelEischer/fix-fsync-warning
Fix inverted condition for fsync warning
This commit is contained in:
commit
0cd077f4ab
3 changed files with 18 additions and 6 deletions
9
changelog/unreleased/issue-230
Normal file
9
changelog/unreleased/issue-230
Normal file
|
@ -0,0 +1,9 @@
|
|||
Bugfix: Fix erroneous warnings about unsupported fsync
|
||||
|
||||
Due to a regression in rest-server 0.12.0, it continuously printed
|
||||
`WARNING: fsync is not supported by the data storage. This can lead to data loss,
|
||||
if the system crashes or the storage is unexpectedly disconnected.` for systems
|
||||
that support fsync. We have fixed the warning.
|
||||
|
||||
https://github.com/restic/rest-server/issues/230
|
||||
https://github.com/restic/rest-server/pull/231
|
|
@ -7,6 +7,7 @@ import (
|
|||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/restic/rest-server/quota"
|
||||
"github.com/restic/rest-server/repo"
|
||||
|
@ -34,6 +35,7 @@ type Server struct {
|
|||
|
||||
htpasswdFile *HtpasswdFile
|
||||
quotaManager *quota.Manager
|
||||
fsyncWarning sync.Once
|
||||
}
|
||||
|
||||
// MaxFolderDepth is the maxDepth param passed to splitURLPath.
|
||||
|
@ -91,6 +93,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
QuotaManager: s.quotaManager, // may be nil
|
||||
PanicOnError: s.PanicOnError,
|
||||
NoVerifyUpload: s.NoVerifyUpload,
|
||||
FsyncWarning: &s.fsyncWarning,
|
||||
}
|
||||
if s.Prometheus {
|
||||
opt.BlobMetricFunc = makeBlobMetricFunc(username, folderPath)
|
||||
|
|
12
repo/repo.go
12
repo/repo.go
|
@ -39,6 +39,7 @@ type Options struct {
|
|||
|
||||
BlobMetricFunc BlobMetricFunc
|
||||
QuotaManager *quota.Manager
|
||||
FsyncWarning *sync.Once
|
||||
}
|
||||
|
||||
// DefaultDirMode is the file mode used for directory creation if not
|
||||
|
@ -74,8 +75,6 @@ func New(path string, opt Options) (*Handler, error) {
|
|||
type Handler struct {
|
||||
path string // filesystem path of repo
|
||||
opt Options
|
||||
|
||||
fsyncWarning sync.Once
|
||||
}
|
||||
|
||||
// httpDefaultError write a HTTP error with the default description
|
||||
|
@ -638,15 +637,16 @@ func (h *Handler) saveBlob(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !syncNotSup {
|
||||
if syncNotSup {
|
||||
h.opt.FsyncWarning.Do(func() {
|
||||
log.Print("WARNING: fsync is not supported by the data storage. This can lead to data loss, if the system crashes or the storage is unexpectedly disconnected.")
|
||||
})
|
||||
} else {
|
||||
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.fsyncWarning.Do(func() {
|
||||
log.Print("WARNING: fsync is not supported by the data storage. This can lead to data loss, if the system crashes or the storage is unexpectedly disconnected.")
|
||||
})
|
||||
}
|
||||
|
||||
h.sendMetric(objectType, BlobWrite, uint64(written))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue