Implemented the "createFolder(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 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
|
||||
|
||||
Reference in New Issue
Block a user