From da95ede80704e667f75372e2142de4cef1dd42da Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Sun, 16 Mar 2025 17:31:55 -0400 Subject: [PATCH] Add utility function for performing basic path validation for adding new entries --- core/utilitiesMisc.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/utilitiesMisc.go b/core/utilitiesMisc.go index 38c6c96..d6da843 100644 --- a/core/utilitiesMisc.go +++ b/core/utilitiesMisc.go @@ -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. // 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).