hasher: fix error from trying to stop an already-stopped db

Before this change, Hasher would sometimes try to stop a bolt db that was
already stopped, resulting in an error. This change fixes the issue by checking
first whether the db is already stopped.

https://forum.rclone.org/t/hasher-with-gdrive-backend-does-not-return-sha1-sha256-for-old-files/44680/11?u=nielash
This commit is contained in:
nielash 2024-02-22 09:56:02 -05:00 committed by Nick Craig-Wood
parent ac830ddd42
commit ff0acfb568
3 changed files with 11 additions and 1 deletions

View File

@ -439,7 +439,7 @@ func (f *Fs) DirMove(ctx context.Context, src fs.Fs, srcRemote, dstRemote string
// Shutdown the backend, closing any background tasks and any cached connections.
func (f *Fs) Shutdown(ctx context.Context) (err error) {
if f.db != nil {
if f.db != nil && !f.db.IsStopped() {
err = f.db.Stop(false)
}
if do := f.Fs.Features().Shutdown; do != nil {

View File

@ -293,6 +293,11 @@ func (db *DB) Stop(remove bool) error {
return db.Do(false, &opStop{remove: remove})
}
// IsStopped returns true if db is already stopped
func (db *DB) IsStopped() bool {
return len(dbMap) == 0
}
// opStop: close database and stop operation loop
type opStop struct {
remove bool

View File

@ -36,5 +36,10 @@ func (*DB) Stop(remove bool) error {
return ErrUnsupported
}
// IsStopped returns true if db is already stopped
func (db *DB) IsStopped() bool {
return true
}
// Exit stops all databases
func Exit() {}