Commit 679fb327 authored by Jonny Schäfer's avatar Jonny Schäfer
Browse files

Modified storeCreateDirectory. Removed unused variables.

parent afa8a13d
Pipeline #189 skipped
......@@ -7,33 +7,27 @@ import (
"path/filepath"
)
var storeFile = "" // TODO: User Directory
var (
storeDefaultPlayer = ""
storeDefaultSubscriptions = ""
storeDefaultPlayer = "" // Contains path created by init()
storeDefaultSubscriptions = "" // Contains path created by init()
)
// init checks if the directories exist and creates them if necessary
// init checks if the configuration directory exist and creates
// it if necessary. It also initializes the global variables
// storeDefaultPlayer = ~/.config/tubus/subscriptions
// storeDefaultSubscriptions = ~/.config/tubus/player
func init() {
user, err := user.Current()
errorCare(err)
home := user.HomeDir
conf := filepath.Join(home, ".config")
conf := filepath.Join(home, ".config/tubus")
exists, err := storeFileExists(conf)
errorCare(err)
if !exists {
errorCare(storeCreateDirectory(conf))
}
conf = filepath.Join(conf, "tubus")
exists, err = storeFileExists(conf)
errorCare(err)
if !exists {
errorCare(storeCreateDirectory(conf))
}
storeDefaultSubscriptions = filepath.Join(conf, "subscriptions")
exists, err = storeFileExists(storeDefaultSubscriptions)
if !exists {
......@@ -45,19 +39,19 @@ func init() {
if !exists {
errorCare(storeCreateFile(storeDefaultPlayer))
}
}
// storeCreateDirectory creates an empty file
// storeCreateDirectory creates an empty file.
func storeCreateFile(path string) error {
file, err := os.Create(path)
file.Close()
return err
}
// storeCreateDirectory creates a file
// storeCreateDirectory creates the given new directory and parent
// directories if needed.
func storeCreateDirectory(path string) error {
return os.Mkdir(path, os.ModePerm)
return os.MkdirAll(path, os.ModePerm)
}
// storeWriteFile writes a file with the given content
......@@ -65,7 +59,7 @@ func storeWriteFile(file, content string) error {
return ioutil.WriteFile(file, []byte(content), os.ModePerm)
}
// storeReadFile returns the content of the given file
// storeReadFile returns the content of the given file.
func storeReadFile(file string) (content string, err error) {
cnt, err := ioutil.ReadFile(file)
content = string(cnt)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment