summaryrefslogtreecommitdiff
path: root/model/storage.go
blob: c0d155dc17180c46d58d9d18a4ee2b13cbadde26 (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
package model

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

type Storage struct {
	Path string
}

func (s Storage) Exists() bool {
	_, err := os.Stat(s.Path)
	return !os.IsNotExist(err)
}

func (s Storage) Create() {
	err := os.Mkdir(s.Path, 0750)
	if err != nil {
		log.Fatal(err)
	}
}

func (s *Storage) Init(version string) {
	if version != "" {
		vp := filepath.Join(s.Path, "version.txt")
		err := os.WriteFile(vp, []byte(version+"\n"), 0644)
		if err != nil {
			log.Fatal(err)
		}
	}
}