mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 00:13:49 +01:00
backend/hasher: add read-only flag
This commit is contained in:
parent
359989a5f7
commit
e4214bac60
@ -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
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user