backend/hasher: add read-only flag

This commit is contained in:
ParasRaba155 2024-07-31 15:04:10 +05:30
parent 359989a5f7
commit e4214bac60
2 changed files with 12 additions and 1 deletions

View File

@ -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

View File

@ -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.