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() {}