summaryrefslogtreecommitdiff
path: root/model
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2024-05-01 13:19:05 +0200
committerxengineering <me@xengineering.eu>2024-05-01 13:19:05 +0200
commit4cc0677b79edeed05ead23def152ac45f35f556d (patch)
treef7be89d40f09cb2427f3f7607a03d46ed1bacc7d /model
parentf9117c3740a134ce544f5a70bcf5b5da06d976da (diff)
downloadceres-4cc0677b79edeed05ead23def152ac45f35f556d.tar
ceres-4cc0677b79edeed05ead23def152ac45f35f556d.tar.zst
ceres-4cc0677b79edeed05ead23def152ac45f35f556d.zip
Use default storage path instead of temp dir
Diffstat (limited to 'model')
-rw-r--r--model/database.go2
-rw-r--r--model/storage.go24
2 files changed, 12 insertions, 14 deletions
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)
}
}