Implemented the CreatedRootFolderTask task in the Library target.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user