diff --git a/Sources/tart/Config.swift b/Sources/tart/Config.swift index 6739fec..c7d0899 100644 --- a/Sources/tart/Config.swift +++ b/Sources/tart/Config.swift @@ -1,11 +1,23 @@ import Foundation struct Config { - public static let tartHomeDir: URL = FileManager.default - .homeDirectoryForCurrentUser - .appendingPathComponent(".tart", isDirectory: true) + let tartHomeDir: URL + let tartCacheDir: URL - public static let tartCacheDir: URL = tartHomeDir.appendingPathComponent("cache", isDirectory: true) + init() { + var tartHomeDir: URL + + if let customTartHome = ProcessInfo.processInfo.environment["TART_HOME"] { + tartHomeDir = URL(fileURLWithPath: customTartHome) + } else { + tartHomeDir = FileManager.default + .homeDirectoryForCurrentUser + .appendingPathComponent(".tart", isDirectory: true) + } + + self.tartHomeDir = tartHomeDir + tartCacheDir = tartHomeDir.appendingPathComponent("cache", isDirectory: true) + } static func jsonEncoder() -> JSONEncoder { let encoder = JSONEncoder() diff --git a/Sources/tart/VM.swift b/Sources/tart/VM.swift index 3072384..76c3bc0 100644 --- a/Sources/tart/VM.swift +++ b/Sources/tart/VM.swift @@ -53,7 +53,7 @@ class VM: NSObject, VZVirtualMachineDelegate, ObservableObject { } - let ipswCacheFolder = Config.tartCacheDir.appendingPathComponent("IPSWs", isDirectory: true) + let ipswCacheFolder = Config().tartCacheDir.appendingPathComponent("IPSWs", isDirectory: true) try FileManager.default.createDirectory(at: ipswCacheFolder, withIntermediateDirectories: true) let expectedIPSWLocation = ipswCacheFolder.appendingPathComponent("\(image.buildVersion).ipsw", isDirectory: false) diff --git a/Sources/tart/VMStorageLocal.swift b/Sources/tart/VMStorageLocal.swift index a5ed92b..7126492 100644 --- a/Sources/tart/VMStorageLocal.swift +++ b/Sources/tart/VMStorageLocal.swift @@ -1,7 +1,7 @@ import Foundation class VMStorageLocal { - let baseURL: URL = Config.tartHomeDir.appendingPathComponent("vms", isDirectory: true) + let baseURL: URL = Config().tartHomeDir.appendingPathComponent("vms", isDirectory: true) private func vmURL(_ name: String) -> URL { baseURL.appendingPathComponent(name, isDirectory: true) diff --git a/Sources/tart/VMStorageOCI.swift b/Sources/tart/VMStorageOCI.swift index 208e3f6..48fc79d 100644 --- a/Sources/tart/VMStorageOCI.swift +++ b/Sources/tart/VMStorageOCI.swift @@ -1,7 +1,7 @@ import Foundation class VMStorageOCI { - let baseURL = Config.tartCacheDir.appendingPathComponent("OCIs", isDirectory: true) + let baseURL = Config().tartCacheDir.appendingPathComponent("OCIs", isDirectory: true) private func vmURL(_ name: RemoteName) -> URL { baseURL.appendingRemoteName(name)