diff options
| -rw-r--r-- | go-src/folderPaths/folderPaths.go | 11 | ||||
| -rw-r--r-- | go-src/utils/utils.go | 14 |
2 files changed, 20 insertions, 5 deletions
diff --git a/go-src/folderPaths/folderPaths.go b/go-src/folderPaths/folderPaths.go index b39ce87..7a8f5cc 100644 --- a/go-src/folderPaths/folderPaths.go +++ b/go-src/folderPaths/folderPaths.go @@ -3,21 +3,22 @@ package folderPaths import ( "os" "runtime" + + "gitlab.com/Syndamia/ctfc/go-src/utils" ) func InitFoldersAndFiles() { dirs := []string{rootFolder(), FileAtChatsFolder(""), FileAtDirectMessagesFolder(""), FileAtUsersFolder("")} for _, v := range dirs { - if _, err := os.Stat(v); os.IsNotExist(err) { - os.Mkdir(v, 0775) + if !utils.PathExists(v) { + utils.CreateDir(v) } } files := []string{AllChatsFilePath()} for _, v := range files { - if _, err := os.Stat(v); os.IsNotExist(err) { - f, _ := os.Create(v) - f.Close() + if !utils.PathExists(v) { + utils.CreateFile(v) } } } diff --git a/go-src/utils/utils.go b/go-src/utils/utils.go index 7b7314e..d6fc47c 100644 --- a/go-src/utils/utils.go +++ b/go-src/utils/utils.go @@ -35,6 +35,20 @@ func AppendToFile(path string, value string) { allChatsFile.Close() } +func CreateDir(path string) { + os.Mkdir(path, 0775) +} + +func CreateFile(path string) { + f, _ := os.Create(path) + f.Close() +} + +func PathExists(path string) bool { + _, err := os.Stat(path) + return !os.IsNotExist(err) +} + func StrShortenRight(s *string, amount int) { *s = (*s)[:len(*s)-amount] } |
