feat(init): Continue Init with directory creation

This commit is contained in:
Matthieu 'JP' DERASSE
2022-08-02 20:30:46 +00:00
parent cc0e94690e
commit 5434cc15ce
6 changed files with 37 additions and 11 deletions

View File

@ -1,3 +1,4 @@
// Package helpers contains all basic function that might make development easier / avoid code duplication
package helpers
const configFile = ".gouick.yaml"

View File

@ -284,7 +284,7 @@ func (g Golang) PostInstall(path string) error {
log.Debug("creating gopath directory")
err = helpers.CheckAndCreateDir(filepath.Join(homeDir, "go"))
_, err = helpers.CheckAndCreateDir(filepath.Join(homeDir, "go"))
if err != nil {
return errors.Trace(err)
}

View File

@ -101,27 +101,28 @@ func createDirectory(path string) error {
}
// CheckAndCreateDir will check if path is writable and create directory if needed
func CheckAndCreateDir(path string) error {
// return a bool true if directory created, false if not
func CheckAndCreateDir(path string) (bool, error) {
dirWritable, err := isDirectoryWritable(path)
if dirWritable {
return nil
return false, nil
} else if err != nil && !errors.Is(err, errors.NotFound) {
log.Warnf("impossible to check if the directory is writable")
return err
return false, err
} else if err == nil && !dirWritable {
log.Warnf("directory is not writable")
return errors.Forbiddenf("directory is not writable")
return false, errors.Forbiddenf("directory is not writable")
}
err = createDirectory(path)
if err != nil {
log.Warnf("impossible to create directory (%s), please try again", err.Error())
return err
return false, err
}
return nil
return true, nil
}
func RemoveDirectoryContent(path string) error {

View File

@ -93,7 +93,7 @@ func PathInput() string {
continue
}
err := CheckAndCreateDir(userInput)
_, err := CheckAndCreateDir(userInput)
if err != nil {
log.Warnf("please, try again")
continue