feat: Fixes not creating default config directory

This commit is contained in:
2024-12-12 12:37:14 -05:00
parent 7b30b78b67
commit 56a0bca00c
6 changed files with 85 additions and 35 deletions

View File

@@ -12,9 +12,11 @@ public extension DependencyValues {
@DependencyClient
public struct FileClient: Sendable {
public var copy: @Sendable (URL, URL) async throws -> Void
public var createDirectory: @Sendable (URL) async throws -> Void
public var fileExists: @Sendable (URL) -> Bool = { _ in true }
public var findVaultFileInCurrentDirectory: @Sendable () async throws -> URL?
public var homeDirectory: @Sendable () -> URL = { URL(filePath: "~/") }
public var isDirectory: @Sendable (URL) async throws -> Bool
public var load: @Sendable (URL) async throws -> Data
public var write: @Sendable (Data, URL) async throws -> Void
}
@@ -26,12 +28,16 @@ extension FileClient: DependencyKey {
let manager = LiveFileClient()
return .init {
try await manager.copy($0, to: $1)
} createDirectory: {
try await manager.creatDirectory($0)
} fileExists: { url in
manager.fileExists(at: url)
} findVaultFileInCurrentDirectory: {
try await manager.findVaultFileInCurrentDirectory()
} homeDirectory: {
manager.homeDirectory()
} isDirectory: {
manager.isDirectory($0)
} load: { url in
try await manager.load(from: url)
} write: { data, url in
@@ -48,6 +54,10 @@ struct LiveFileClient: Sendable {
try manager.copyItem(at: url, to: toUrl)
}
func creatDirectory(_ url: URL) async throws {
try manager.createDirectory(at: url, withIntermediateDirectories: true)
}
func fileExists(at url: URL) -> Bool {
manager.fileExists(atPath: url.cleanFilePath)
}
@@ -78,7 +88,7 @@ struct LiveFileClient: Sendable {
manager.homeDirectoryForCurrentUser
}
private func isDirectory(_ url: URL) -> Bool {
func isDirectory(_ url: URL) -> Bool {
var isDirectory: ObjCBool = false
manager.fileExists(atPath: url.cleanFilePath, isDirectory: &isDirectory)
return isDirectory.boolValue