From d4b3d2fafb86c3098252c7195e63ffb7bff8befb Mon Sep 17 00:00:00 2001 From: jholdstock Date: Thu, 31 Mar 2022 09:30:51 +0100 Subject: [PATCH] Make writeHotBackupFile a method of VspDatabase. No reason for this to be a standalone func with a param when it can be a method of VspDatabase. This will be useful later when VspDatabase contains its own logger. --- database/database.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/database/database.go b/database/database.go index 5a99172..93c28c1 100644 --- a/database/database.go +++ b/database/database.go @@ -62,15 +62,15 @@ var backupMtx sync.Mutex // writeHotBackupFile writes a backup of the database file while the database // is still open. -func writeHotBackupFile(db *bolt.DB) error { +func (vdb *VspDatabase) writeHotBackupFile() error { backupMtx.Lock() defer backupMtx.Unlock() - backupPath := db.Path() + "-backup" + backupPath := vdb.db.Path() + "-backup" tempPath := backupPath + "~" // Write backup to temporary file. - err := db.View(func(tx *bolt.Tx) error { + err := vdb.db.View(func(tx *bolt.Tx) error { return tx.CopyFile(tempPath, backupFileMode) }) if err != nil { @@ -207,7 +207,7 @@ func Open(ctx context.Context, shutdownWg *sync.WaitGroup, dbFile string, backup for { select { case <-time.After(backupInterval): - err := writeHotBackupFile(db) + err := vdb.writeHotBackupFile() if err != nil { log.Errorf("Failed to write database backup: %v", err) }