Skip to content

Commit

Permalink
Merge pull request #146 from spurin/dont_create_snapshot_if_doesnt_exist
Browse files Browse the repository at this point in the history
check file exists before using bolt.Open
  • Loading branch information
jmhbnz authored Nov 4, 2024
2 parents afa7de3 + fa96b35 commit 54e202a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/data/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"encoding/json"
"fmt"
"hash/crc32"
"os"
"sort"
"strings"
"text/template"
Expand Down Expand Up @@ -151,7 +152,15 @@ type Checksum struct {
CompactRevision int64
}

// boltOpen checks if the file exists and opens it in read-only mode.
// Returns an error if the file does not exist.
func boltOpen(path string) (*bolt.DB, error) {
// Check if the file exists
if _, err := os.Stat(path); os.IsNotExist(err) {
return nil, fmt.Errorf("file does not exist: %s", path)
}

// Open the file in read-only mode
return bolt.Open(path, 0400, &bolt.Options{
ReadOnly: true,
})
Expand Down

0 comments on commit 54e202a

Please sign in to comment.