Improved the naming of the functions for the FileServicing protocol in the library target.

This commit is contained in:
2025-01-13 23:27:50 +01:00
parent df556f83ab
commit 26fde119ef
6 changed files with 69 additions and 69 deletions
+13 -16
View File
@@ -22,39 +22,36 @@ public struct FileService: FileServicing {
// MARK: Functions
public func createFolder(at url: URL) async throws (FileServiceError) {
guard try await !exists(at: url) else {
throw FileServiceError.urlAlreadyExists
public func createFolder(at location: URL) async throws (FileServiceError) {
guard try await !isItemExists(at: location) else {
throw FileServiceError.itemAlreadyExists
}
do {
try fileManager.createDirectory(
at: url,
withIntermediateDirectories: true
)
try fileManager.createDirectory(at: location, withIntermediateDirectories: true)
} catch {
throw FileServiceError.folderNotCreated
}
}
public func delete(at url: URL) async throws (FileServiceError) {
guard try await exists(at: url) else {
throw FileServiceError.urlNotExists
public func deleteItem(at location: URL) async throws (FileServiceError) {
guard try await isItemExists(at: location) else {
throw FileServiceError.itemNotExists
}
do {
try fileManager.removeItem(at: url)
try fileManager.removeItem(at: location)
} catch {
throw FileServiceError.urlNotDeleted
throw FileServiceError.itemNotDeleted
}
}
public func exists(at url: URL) async throws (FileServiceError) -> Bool {
guard url.isFileURL else {
throw FileServiceError.urlNotFileURL
public func isItemExists(at location: URL) async throws (FileServiceError) -> Bool {
guard location.isFileURL else {
throw FileServiceError.itemNotFileURL
}
let filePath = url.pathString
let filePath = location.pathString
return fileManager.fileExists(atPath: filePath)
}