Skip to content

Commit 392d133

Browse files
committed
Update store.go
1 parent 4aaf1ec commit 392d133

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

pkg/vectorstore/store.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"os"
1212
"path/filepath"
1313
"sort"
14+
"strings"
1415

1516
_ "github.com/mattn/go-sqlite3"
1617
)
@@ -228,7 +229,7 @@ func (vs *VectorStore) MarkVerified(id int64, verified bool) error {
228229
return err
229230
}
230231

231-
// Close closes the database connection
232+
// Close closes the database connection and cleans up ephemeral storage.
232233
func (vs *VectorStore) Close() error {
233234
if vs.db != nil {
234235
if err := vs.db.Close(); err != nil {
@@ -237,9 +238,24 @@ func (vs *VectorStore) Close() error {
237238
}
238239

239240
if vs.enabled && vs.ephemeral && vs.dbPath != "" {
241+
// Remove the main DB file
240242
if err := os.Remove(vs.dbPath); err != nil && !errors.Is(err, os.ErrNotExist) {
241243
return err
242244
}
245+
246+
// Best-effort cleanup of SQLite sidecar files
247+
if strings.HasSuffix(vs.dbPath, ".db") {
248+
_ = os.Remove(vs.dbPath + "-shm")
249+
_ = os.Remove(vs.dbPath + "-wal")
250+
}
251+
252+
// If the directory is now empty, remove it to avoid leaving
253+
// stale .gosecretscanner/ folders and lock files lying around.
254+
dir := filepath.Dir(vs.dbPath)
255+
entries, err := os.ReadDir(dir)
256+
if err == nil && len(entries) == 0 {
257+
_ = os.Remove(dir)
258+
}
243259
}
244260

245261
return nil

0 commit comments

Comments
 (0)