Implemented the "delete(at: )" function for the FileService service in the module target.
This commit is contained in:
@@ -8,6 +8,7 @@ public protocol FileServicing {
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
func delete(at url: URL) async throws (FileServiceError)
|
||||
func exists(at url: URL) async throws (FileServiceError) -> Bool
|
||||
|
||||
}
|
||||
@@ -16,8 +17,8 @@ public protocol FileServicing {
|
||||
|
||||
public enum FileServiceError: Error, Equatable {
|
||||
case folderNotCreated
|
||||
case folderNotDeleted
|
||||
case urlAlreadyExists
|
||||
case urlNotDeleted
|
||||
case urlNotExists
|
||||
case urlNotFileURL
|
||||
}
|
||||
|
||||
@@ -20,6 +20,20 @@ public struct FileService: FileServicing {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
public func delete(at url: URL) async throws (FileServiceError) {
|
||||
guard try await exists(at: url) else {
|
||||
throw FileServiceError.urlNotExists
|
||||
}
|
||||
|
||||
do {
|
||||
try fileManager.removeItem(at: url)
|
||||
} catch {
|
||||
throw FileServiceError.urlNotDeleted
|
||||
}
|
||||
}
|
||||
|
||||
public func exists(at url: URL) async throws (FileServiceError) -> Bool {
|
||||
guard url.isFileURL else {
|
||||
throw FileServiceError.urlNotFileURL
|
||||
|
||||
Reference in New Issue
Block a user