colibri/Sources/Library/Tasks/CreateRootFolderTask.swift

39 lines
836 B
Swift

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
}
}