Implemented the CreatedRootFolderTask task in the Library target.

This commit is contained in:
2025-01-11 18:40:09 +01:00
parent 3f98d08a00
commit af1703e6c1
5 changed files with 119 additions and 19 deletions
@@ -0,0 +1,38 @@
import Foundation
public struct CreateRootFolderTask {
// MARK: Properties
private let fileService: FileServicing
// MARK: Initialisers
public init(fileService: FileServicing) {
self.fileService = fileService
}
// MARK: Functions
public func callAsFunction(
name: String,
at location: URL? = nil
) async throws -> URL {
let rootFolder = if let location {
location
} else {
await fileService.currentFolder
}
let newFolder = if #available(macOS 13.0, *) {
rootFolder.appending(path: name)
} else {
rootFolder.appendingPathComponent(name)
}
try await fileService.createFolder(at: newFolder)
return newFolder
}
}