feat(init): Continue Init with directory creation
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
// Package helpers contains all basic function that might make development easier / avoid code duplication
|
||||
package helpers
|
||||
|
||||
const configFile = ".gouick.yaml"
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -93,7 +93,7 @@ func PathInput() string {
|
||||
continue
|
||||
}
|
||||
|
||||
err := CheckAndCreateDir(userInput)
|
||||
_, err := CheckAndCreateDir(userInput)
|
||||
if err != nil {
|
||||
log.Warnf("please, try again")
|
||||
continue
|
||||
|
Reference in New Issue
Block a user