Skip to content

Commit 6962ac7

Browse files
authored
Verify user access to config file (#80)
1 parent 6326549 commit 6962ac7

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

config/config.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,22 @@ func (c Config) CacheFile() string {
9797
return path.Join(cacheDir, cacheFileName)
9898
}
9999

100+
func hasAccess(path string) bool {
101+
status := true
102+
file, err := os.Open(path)
103+
if (err != nil) {
104+
status = false
105+
}
106+
file.Close()
107+
return status
108+
}
109+
100110
func checkAndCreateDir(path string) string {
111+
isAccsessible := hasAccess(path)
112+
if !isAccsessible {
113+
fmt.Println("User isn't authorized to access the config file")
114+
os.Exit(1)
115+
}
101116
if fileInfo, err := os.Stat(path); os.IsNotExist(err) || !fileInfo.IsDir() {
102117
err := os.Mkdir(path, 0700)
103118
if err != nil {

0 commit comments

Comments
 (0)