diff options
author | xengineering <me@xengineering.eu> | 2024-05-04 20:22:23 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2024-05-04 20:22:23 +0200 |
commit | c6fbbbded8463fc94e5af223246eac97d538a9e5 (patch) | |
tree | 0ada93ea3746197968964edf6d95f930f398e0c8 /model/storage.go | |
parent | 7d8899e1d2bf45511d10670dd9a6ad386afb8da1 (diff) | |
download | ceres-c6fbbbded8463fc94e5af223246eac97d538a9e5.tar ceres-c6fbbbded8463fc94e5af223246eac97d538a9e5.tar.zst ceres-c6fbbbded8463fc94e5af223246eac97d538a9e5.zip |
model: Add storage.Exists() and storage.Create()
These new methods provide essential functionality related to the storage
folder.
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) } |