diff --git a/db/swappable_db.go b/db/swappable_db.go index c1ca52bf..d619e546 100644 --- a/db/swappable_db.go +++ b/db/swappable_db.go @@ -25,7 +25,9 @@ func OpenSwappable(dbPath string, fkEnabled, wal bool) (*SwappableDB, error) { return &SwappableDB{db: db}, nil } -// Swap swaps the underlying database with that at the given path. +// Swap swaps the underlying database with that at the given path. The Swap operation +// may fail on some platforms if the file at path is open by another process. It is +// the caller's responsibility to ensure the file at path is not in use. func (s *SwappableDB) Swap(path string, fkConstraints, walEnabled bool) error { if !IsValidSQLiteFile(path) { return fmt.Errorf("invalid SQLite data") diff --git a/db/swappable_db_test.go b/db/swappable_db_test.go index 51837f58..c3410de9 100644 --- a/db/swappable_db_test.go +++ b/db/swappable_db_test.go @@ -75,6 +75,9 @@ func Test_SwapSuccess(t *testing.T) { defer swappableDB.Close() // Perform the swap + if err := srcDB.Close(); err != nil { + t.Fatalf("failed to close source database pre-swap: %s", err) + } if err := swappableDB.Swap(srcPath, false, false); err != nil { t.Fatalf("failed to swap database: %s", err) }