summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.go6
-rw-r--r--model/database.go2
-rw-r--r--model/storage.go24
3 files changed, 15 insertions, 17 deletions
diff --git a/main.go b/main.go
index 0c82a7c..2eb3342 100644
--- a/main.go
+++ b/main.go
@@ -29,10 +29,10 @@ func main() {
os.Exit(0)
}
- model.InitStorage(gitDescribe)
- defer model.RemoveStorage()
+ model.InitStorage(config.StorageFilePath, gitDescribe)
+ defer model.RemoveStorage(config.StorageFilePath)
- model.InitDatabase()
+ model.InitDatabase(config.StorageFilePath)
defer model.CloseDatabase()
model.InjectTestRecipes()
diff --git a/model/database.go b/model/database.go
index 3d8a0c4..36190ff 100644
--- a/model/database.go
+++ b/model/database.go
@@ -23,7 +23,7 @@ func GetSql(code string) (string, error) {
return string(query), nil
}
-func InitDatabase() {
+func InitDatabase(storage string) {
var err error
fn := filepath.Join(storage, "ceres.sqlite3")
diff --git a/model/storage.go b/model/storage.go
index 2ce2fdf..e7d1fbc 100644
--- a/model/storage.go
+++ b/model/storage.go
@@ -6,32 +6,30 @@ import (
"path/filepath"
)
-var storage string
-
-func InitStorage(version string) {
- var err error
-
- storage, err = os.MkdirTemp("", "ceres-")
- if err != nil {
+func InitStorage(path string, version string) {
+ err := os.Mkdir(path, 0750)
+ if err != nil && !os.IsExist(err) {
log.Fatal(err)
}
+ log.Printf("Created storage folder %s\n", path)
+
if version != "" {
- vp := filepath.Join(storage, "version.txt")
+ vp := filepath.Join(path, "version.txt")
err = os.WriteFile(vp, []byte(version+"\n"), 0644)
if err != nil {
log.Fatal(err)
}
}
- log.Printf("Storage directory: %s\n", storage)
+ log.Printf("Storage directory: %s\n", path)
}
-func RemoveStorage() {
- var err error = os.RemoveAll(storage)
+func RemoveStorage(path string) {
+ var err error = os.RemoveAll(path)
if err != nil {
- log.Printf("Failed to remove temporary storage folder: %v\n", err)
+ log.Printf("Failed to remove storage folder: %v\n", err)
} else {
- log.Println("Removed temporary storage folder")
+ log.Printf("Removed storage folder %s\n", path)
}
}