summaryrefslogtreecommitdiff
path: root/model/storage.go
blob: e7d1fbc84c7445020bcf595f1b1fdd78dedffd96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package model

import (
	"log"
	"os"
	"path/filepath"
)

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(path, "version.txt")
		err = os.WriteFile(vp, []byte(version+"\n"), 0644)
		if err != nil {
			log.Fatal(err)
		}
	}

	log.Printf("Storage directory: %s\n", path)
}

func RemoveStorage(path string) {
	var err error = os.RemoveAll(path)
	if err != nil {
		log.Printf("Failed to remove storage folder: %v\n", err)
	} else {
		log.Printf("Removed storage folder %s\n", path)
	}
}