Skip to content

Commit fa96b35

Browse files
committed
check file exists before using bolt.Open
Signed-off-by: James Spurin <[email protected]>
1 parent afa7de3 commit fa96b35

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

pkg/data/data.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"encoding/json"
2323
"fmt"
2424
"hash/crc32"
25+
"os"
2526
"sort"
2627
"strings"
2728
"text/template"
@@ -151,7 +152,15 @@ type Checksum struct {
151152
CompactRevision int64
152153
}
153154

155+
// boltOpen checks if the file exists and opens it in read-only mode.
156+
// Returns an error if the file does not exist.
154157
func boltOpen(path string) (*bolt.DB, error) {
158+
// Check if the file exists
159+
if _, err := os.Stat(path); os.IsNotExist(err) {
160+
return nil, fmt.Errorf("file does not exist: %s", path)
161+
}
162+
163+
// Open the file in read-only mode
155164
return bolt.Open(path, 0400, &bolt.Options{
156165
ReadOnly: true,
157166
})

0 commit comments

Comments
 (0)