File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed
Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff 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.
232233func (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
You can’t perform that action at this time.
0 commit comments