From 7cbe33ae59757d67a6b31030aef0769f86acf3c2 Mon Sep 17 00:00:00 2001 From: xengineering Date: Wed, 1 May 2024 11:21:04 +0200 Subject: model: Add version.txt file to storage folder This prepares the ability to check for compatibility between a Ceres executable build and an existing storage folder. --- main.go | 2 +- model/storage.go | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 50cfce5..4947fc8 100644 --- a/main.go +++ b/main.go @@ -29,7 +29,7 @@ func main() { os.Exit(0) } - model.InitStorage() + model.InitStorage(gitDescribe) defer model.RemoveStorage() model.InitDatabase() diff --git a/model/storage.go b/model/storage.go index 39539d4..2ce2fdf 100644 --- a/model/storage.go +++ b/model/storage.go @@ -3,11 +3,12 @@ package model import ( "log" "os" + "path/filepath" ) var storage string -func InitStorage() { +func InitStorage(version string) { var err error storage, err = os.MkdirTemp("", "ceres-") @@ -15,6 +16,14 @@ func InitStorage() { log.Fatal(err) } + if version != "" { + vp := filepath.Join(storage, "version.txt") + err = os.WriteFile(vp, []byte(version+"\n"), 0644) + if err != nil { + log.Fatal(err) + } + } + log.Printf("Storage directory: %s\n", storage) } -- cgit v1.2.3-70-g09d2