diff --git a/backend/hasher/hasher.go b/backend/hasher/hasher.go index 3cd75a5c7..2e7aa64cc 100644 --- a/backend/hasher/hasher.go +++ b/backend/hasher/hasher.go @@ -50,6 +50,10 @@ func init() { Advanced: true, Default: fs.SizeSuffix(0), Help: "Auto-update checksum for files smaller than this size (disabled by default).", + }, { + Name: "read_only", + Default: false, + Help: "Set the db in read only mode", }}, }) } @@ -60,6 +64,7 @@ type Options struct { Hashes fs.CommaSepList `config:"hashes"` AutoSize fs.SizeSuffix `config:"auto_size"` MaxAge fs.Duration `config:"max_age"` + ReadOnly bool `config:"read_only"` } // Fs represents a wrapped fs.Fs diff --git a/backend/hasher/object.go b/backend/hasher/object.go index 1003807c8..d46f5a0a2 100644 --- a/backend/hasher/object.go +++ b/backend/hasher/object.go @@ -11,6 +11,7 @@ import ( "github.com/rclone/rclone/fs" "github.com/rclone/rclone/fs/hash" "github.com/rclone/rclone/fs/operations" + "github.com/rclone/rclone/lib/kv" ) // obtain hash for an object @@ -58,12 +59,17 @@ func (o *Object) putHashes(ctx context.Context, rawHashes hashMap) error { // set hashes for a path without any validation func (f *Fs) putRawHashes(ctx context.Context, key, fp string, hashes operations.HashSums) error { - return f.db.Do(true, &kvPut{ + err := f.db.Do(true, &kvPut{ key: key, fp: fp, hashes: hashes, age: time.Duration(f.opt.MaxAge), }) + if f.opt.ReadOnly && errors.Is(err, kv.ErrReadOnly) { + fs.Debugf(nil, "database in read only mode") + return nil + } + return err } // Hash returns the selected checksum of the file or "" if unavailable.