Do not return isFile, as the returned error can be used for this purpose

This commit is contained in:
2025-06-01 14:48:13 -04:00
parent b001ea2a75
commit 71b5056ca6
+7 -7
View File
@@ -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
} }
} }