From aceca8b5dfc8edd378ee9ff891bccb0f94c69f31 Mon Sep 17 00:00:00 2001 From: gigagamerchaddhruv-spec Date: Wed, 14 Oct 2026 20:18:20 +0530 Subject: feat: launch Bubomb - native macOS menu bar utility ('Configure the boom') --- Sources/BubombCore/Utilities/PathValidator.swift | 69 ++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Sources/BubombCore/Utilities/PathValidator.swift (limited to 'Sources/BubombCore/Utilities/PathValidator.swift') diff --git a/Sources/BubombCore/Utilities/PathValidator.swift b/Sources/BubombCore/Utilities/PathValidator.swift new file mode 100644 index 0000000..af8c14c --- /dev/null +++ b/Sources/BubombCore/Utilities/PathValidator.swift @@ -0,0 +1,69 @@ +import Foundation + +/// Utilities for validating filesystem paths and URLs. +public enum PathValidator { + /// Checks whether an executable exists at the given path and is executable. + public static func validateExecutable(at path: String) -> Result { + let expanded = NSString(string: path).expandingTildeInPath + let fileManager = FileManager.default + + guard fileManager.fileExists(atPath: expanded) else { + return .failure(.executableNotFound(expanded)) + } + guard fileManager.isExecutableFile(atPath: expanded) else { + return .failure(.permissionDenied("File is not executable: \(expanded)")) + } + return .success(expanded) + } + + /// Checks whether a script file exists at the given path. + public static func validateScript(at path: String) -> Result { + let expanded = NSString(string: path).expandingTildeInPath + let fileManager = FileManager.default + + guard fileManager.fileExists(atPath: expanded) else { + return .failure(.scriptNotFound(expanded)) + } + guard fileManager.isReadableFile(atPath: expanded) else { + return .failure(.permissionDenied("Script file is not readable: \(expanded)")) + } + return .success(expanded) + } + + /// Checks whether a working directory exists and is a directory. + public static func validateWorkingDirectory(_ path: String?) -> Result { + guard let path = path, !path.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else { + return .success(nil) + } + let expanded = NSString(string: path).expandingTildeInPath + var isDir: ObjCBool = false + if FileManager.default.fileExists(atPath: expanded, isDirectory: &isDir), isDir.boolValue { + return .success(expanded) + } + return .failure(.workingDirectoryNotFound(expanded)) + } + + /// Validates an HTTP or HTTPS URL. + public static func validateURL(_ urlString: String) -> Result { + let trimmed = urlString.trimmingCharacters(in: .whitespacesAndNewlines) + guard let url = URL(string: trimmed), + let scheme = url.scheme?.lowercased(), + (scheme == "http" || scheme == "https"), + url.host != nil, + !(url.host?.isEmpty ?? true) else { + return .failure(.invalidURL(urlString)) + } + return .success(url) + } + + /// Checks if an application bundle exists. + public static func validateApplication(at path: String) -> Result { + let expanded = NSString(string: path).expandingTildeInPath + let fileManager = FileManager.default + + guard fileManager.fileExists(atPath: expanded) else { + return .failure(.applicationNotFound(expanded)) + } + return .success(expanded) + } +} -- cgit v1.2.3