mirror of
https://github.com/rwinkhart/libmutton.git
synced 2026-09-01 14:47:25 -04:00
Add utility function for performing basic path validation for adding new entries
This commit is contained in:
@@ -109,6 +109,18 @@ func ClampTrailingWhitespace(note []string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EntryAddPrecheck ensures the directory meant to contain a new
|
||||||
|
// entry exists and that the target entry location is not already used.
|
||||||
|
func EntryAddPrecheck(targetLocation string) {
|
||||||
|
// ensure target location does not already exist
|
||||||
|
_, isAccessible := TargetIsFile(targetLocation, false, 0)
|
||||||
|
if isAccessible {
|
||||||
|
PrintError("Target location already exists", ErrorTargetExists, false)
|
||||||
|
}
|
||||||
|
// ensure target containing directory exists and is a directory (not a file)
|
||||||
|
TargetIsFile(targetLocation[:strings.LastIndex(targetLocation, PathSeparator)], true, 1)
|
||||||
|
}
|
||||||
|
|
||||||
// StringGen generates a random string of a specified length and complexity.
|
// StringGen generates a random string of a specified length and complexity.
|
||||||
// Requires: complexity (minimum percentage of special characters to be returned in the generated string; only impacts complex strings),
|
// Requires: complexity (minimum percentage of special characters to be returned in the generated string; only impacts complex strings),
|
||||||
// safeForFileName: (if true, the generated string will only contain special characters that are safe for file names; only impacts complex strings).
|
// safeForFileName: (if true, the generated string will only contain special characters that are safe for file names; only impacts complex strings).
|
||||||
|
|||||||
Reference in New Issue
Block a user