mirror of
https://github.com/rwinkhart/go-boilerplate.git
synced 2026-09-06 09:07:15 -04:00
Do not return isFile, as the returned error can be used for this purpose
This commit is contained in:
+7
-7
@@ -9,22 +9,22 @@ import (
|
|||||||
// TargetIsFile checks if the targetLocation is a file, directory, or is inaccessible.
|
// TargetIsFile checks if the targetLocation is a file, directory, or is inaccessible.
|
||||||
// Requires: targetLocation,
|
// Requires: targetLocation,
|
||||||
// failOnDir (whether to return an error if targetLocation is a directory or a file).
|
// failOnDir (whether to return an error if targetLocation is a directory or a file).
|
||||||
// Returns: isFile, isAccessible.
|
// Returns: isAccessible.
|
||||||
func TargetIsFile(targetLocation string, failOnDir bool) (bool, bool, error) {
|
func TargetIsFile(targetLocation string, failOnDir bool) (bool, error) {
|
||||||
targetInfo, err := os.Stat(targetLocation)
|
targetInfo, err := os.Stat(targetLocation)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, false, errors.New("unable to access \"" + targetLocation + "\": " + err.Error())
|
return false, errors.New("unable to access \"" + targetLocation + "\": " + err.Error())
|
||||||
}
|
}
|
||||||
if targetInfo.IsDir() {
|
if targetInfo.IsDir() {
|
||||||
if failOnDir {
|
if failOnDir {
|
||||||
return false, true, errors.New("\"" + targetLocation + "\" is a directory")
|
return true, errors.New("\"" + targetLocation + "\" is a directory")
|
||||||
}
|
}
|
||||||
return false, true, nil
|
return true, nil
|
||||||
} else {
|
} else {
|
||||||
if !failOnDir {
|
if !failOnDir {
|
||||||
return true, true, errors.New("\"" + targetLocation + "\" is a file")
|
return true, errors.New("\"" + targetLocation + "\" is a file")
|
||||||
}
|
}
|
||||||
return true, true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user