-
Notifications
You must be signed in to change notification settings - Fork 0
/
filesystem.go
58 lines (48 loc) · 1.02 KB
/
filesystem.go
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package filesystem
import (
"errors"
"os"
"path/filepath"
)
type (
Filesystem struct {
Archive string
Asset string
Home string
Log string
Preferences string
Settings string
}
)
func NewFilesystem() *Filesystem {
var configuration, _ = os.UserConfigDir()
// Directories
var home = filepath.Join(configuration, "senna")
os.Mkdir(home, os.ModePerm)
var asset = filepath.Join(home, "asset")
os.Mkdir(asset, os.ModePerm)
// Files
var archive = filepath.Join(asset, "asset.zip")
var log = filepath.Join(home, "log.txt")
var preferences = filepath.Join(home, "preferences.json")
var settings = filepath.Join(home, "settings.ini")
return &Filesystem{
Archive: archive,
Asset: asset,
Home: home,
Log: log,
Preferences: preferences,
Settings: settings,
}
}
func (filesystem *Filesystem) Exist(filename string) bool {
_, err := os.OpenFile(
filename,
os.O_RDONLY,
0444,
)
if errors.Is(err, os.ErrNotExist) {
return false
}
return true
}