diff options
Diffstat (limited to 'model/storage.go')
-rw-r--r-- | model/storage.go | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/model/storage.go b/model/storage.go index fcec125..5450c60 100644 --- a/model/storage.go +++ b/model/storage.go @@ -10,17 +10,22 @@ type Storage struct { Path string } -func (s *Storage) Init(version 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 && !os.IsExist(err) { + if err != nil { log.Fatal(err) } +} - log.Printf("Created storage folder %s\n", s.Path) - +func (s *Storage) Init(version string) { if version != "" { vp := filepath.Join(s.Path, "version.txt") - err = os.WriteFile(vp, []byte(version+"\n"), 0644) + err := os.WriteFile(vp, []byte(version+"\n"), 0644) if err != nil { log.Fatal(err) } |