From a9c219fceadd8e187c1a1893f074d72c662d0487 Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Thu, 5 Nov 2026 07:15:24 -0600 Subject: [PATCH] snapshots: create directory if it does not exist --- snapshot.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/snapshot.go b/snapshot.go index dbe1cae..379a4cb 100644 --- a/snapshot.go +++ b/snapshot.go @@ -173,11 +173,19 @@ func (ldb *LiteDB) create(ctx scope.C, opts *SnapshotOptions, now time.Time, sco } func (ldb *LiteDB) touch(path string) error { + // ensure snapshots directory exists with owner-only permissions + directory := filepath.Dir(path) + if err := os.MkdirAll(directory, 0700); err != nil { + return err + } + // ensure the snapshot file exists with owner-only permissions file, err := os.OpenFile(path, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0600) if err != nil { return err } + + // close the file; sqlite will re-open it with the existing permissions return file.Close() }