From ff0acfb568ede3cf4bda9a791bd777398a1bc167 Mon Sep 17 00:00:00 2001 From: nielash Date: Thu, 22 Feb 2024 09:56:02 -0500 Subject: [PATCH] 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 --- backend/hasher/hasher.go | 2 +- lib/kv/bolt.go | 5 +++++ lib/kv/unsupported.go | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/backend/hasher/hasher.go b/backend/hasher/hasher.go index f43c03896..c50f2404a 100644 --- a/backend/hasher/hasher.go +++ b/backend/hasher/hasher.go @@ -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 { diff --git a/lib/kv/bolt.go b/lib/kv/bolt.go index 2a411c3dd..7ae5756ad 100644 --- a/lib/kv/bolt.go +++ b/lib/kv/bolt.go @@ -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 diff --git a/lib/kv/unsupported.go b/lib/kv/unsupported.go index 4bede3fd9..9148a1806 100644 --- a/lib/kv/unsupported.go +++ b/lib/kv/unsupported.go @@ -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() {}