mirror of
https://github.com/rclone/rclone.git
synced 2025-02-16 18:41:54 +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,
|
Advanced: true,
|
||||||
Default: fs.SizeSuffix(0),
|
Default: fs.SizeSuffix(0),
|
||||||
Help: "Auto-update checksum for files smaller than this size (disabled by default).",
|
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"`
|
Hashes fs.CommaSepList `config:"hashes"`
|
||||||
AutoSize fs.SizeSuffix `config:"auto_size"`
|
AutoSize fs.SizeSuffix `config:"auto_size"`
|
||||||
MaxAge fs.Duration `config:"max_age"`
|
MaxAge fs.Duration `config:"max_age"`
|
||||||
|
ReadOnly bool `config:"read_only"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fs represents a wrapped fs.Fs
|
// Fs represents a wrapped fs.Fs
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/rclone/rclone/fs"
|
"github.com/rclone/rclone/fs"
|
||||||
"github.com/rclone/rclone/fs/hash"
|
"github.com/rclone/rclone/fs/hash"
|
||||||
"github.com/rclone/rclone/fs/operations"
|
"github.com/rclone/rclone/fs/operations"
|
||||||
|
"github.com/rclone/rclone/lib/kv"
|
||||||
)
|
)
|
||||||
|
|
||||||
// obtain hash for an object
|
// 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
|
// set hashes for a path without any validation
|
||||||
func (f *Fs) putRawHashes(ctx context.Context, key, fp string, hashes operations.HashSums) error {
|
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,
|
key: key,
|
||||||
fp: fp,
|
fp: fp,
|
||||||
hashes: hashes,
|
hashes: hashes,
|
||||||
age: time.Duration(f.opt.MaxAge),
|
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.
|
// Hash returns the selected checksum of the file or "" if unavailable.
|
||||||
|
Loading…
Reference in New Issue
Block a user