diff --git a/Sources/tart/Root.swift b/Sources/tart/Root.swift index 52d15bd..1eeacfb 100644 --- a/Sources/tart/Root.swift +++ b/Sources/tart/Root.swift @@ -81,10 +81,12 @@ struct Root: AsyncParsableCommand { var command = try parseAsRoot() // Run garbage-collection before each command (shouldn't take too long) - do { - try Config().gc() - } catch { - fputs("Failed to perform garbage collection!\n\(error)\n", stderr) + if type(of: command) != type(of: Pull()) && type(of: command) != type(of: Clone()){ + do { + try Config().gc() + } catch { + fputs("Failed to perform garbage collection!\n\(error)\n", stderr) + } } if var asyncCommand = command as? AsyncParsableCommand { diff --git a/Sources/tart/VMDirectory.swift b/Sources/tart/VMDirectory.swift index abf9e34..ec755f6 100644 --- a/Sources/tart/VMDirectory.swift +++ b/Sources/tart/VMDirectory.swift @@ -1,5 +1,6 @@ import Foundation import Virtualization +import CryptoKit struct VMDirectory: Prunable { var baseURL: URL @@ -59,6 +60,17 @@ struct VMDirectory: Prunable { return VMDirectory(baseURL: tmpDir) } + //Create tmp directory with hashing + static func temporaryDeterministic(key: String) throws -> VMDirectory { + let keyData = Data(key.utf8) + let hash = Insecure.MD5.hash(data: keyData) + // Convert hash to string + let hashString = hash.compactMap { String(format: "%02x", $0) }.joined() + let tmpDir = try Config().tartTmpDir.appendingPathComponent(hashString) + try FileManager.default.createDirectory(at: tmpDir, withIntermediateDirectories: true) + return VMDirectory(baseURL: tmpDir) + } + var initialized: Bool { FileManager.default.fileExists(atPath: configURL.path) && FileManager.default.fileExists(atPath: diskURL.path) && diff --git a/Sources/tart/VMStorageOCI.swift b/Sources/tart/VMStorageOCI.swift index 8660048..d76ece7 100644 --- a/Sources/tart/VMStorageOCI.swift +++ b/Sources/tart/VMStorageOCI.swift @@ -170,7 +170,7 @@ class VMStorageOCI: PrunableStorage { if !exists(digestName) { let transaction = SentrySDK.startTransaction(name: name.description, operation: "pull", bindToScope: true) - let tmpVMDir = try VMDirectory.temporary() + let tmpVMDir = try VMDirectory.temporaryDeterministic(key: name.description) // Lock the temporary VM directory to prevent it's garbage collection let tmpVMDirLock = try FileLock(lockURL: tmpVMDir.baseURL)