Implemented the "createFolder(at: )" function for the FileService service in the module target.

This commit is contained in:
2025-01-11 05:08:06 +01:00
parent 58151a4e5a
commit 1d080cce45
3 changed files with 53 additions and 4 deletions
@@ -8,6 +8,7 @@ public protocol FileServicing {
// MARK: Functions
func createFolder(at url: URL) async throws (FileServiceError)
func delete(at url: URL) async throws (FileServiceError)
func exists(at url: URL) async throws (FileServiceError) -> Bool
@@ -22,6 +22,21 @@ 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
}
do {
try fileManager.createDirectory(
at: url,
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