diff --git a/Sources/tart/Commands/Clone.swift b/Sources/tart/Commands/Clone.swift index 8b4016c7..799c57bc 100644 --- a/Sources/tart/Commands/Clone.swift +++ b/Sources/tart/Commands/Clone.swift @@ -53,7 +53,7 @@ struct Clone: AsyncParsableCommand { // APFS is doing copy-on-write so the above cloning operation (just copying files on disk) // is not actually claiming new space until the VM is started and it writes something to disk. // So once we clone the VM let's try to claim a little bit of space for the VM to run. - try Prune.reclaimIfNeeded(UInt64(sourceVM.sizeBytes())) + try Prune.reclaimIfNeeded(UInt64(sourceVM.sizeBytes()), sourceVM) }, onCancel: { try? FileManager.default.removeItem(at: tmpVMDir.baseURL) }) diff --git a/Sources/tart/Commands/Prune.swift b/Sources/tart/Commands/Prune.swift index ca9dadcc..0521c29f 100644 --- a/Sources/tart/Commands/Prune.swift +++ b/Sources/tart/Commands/Prune.swift @@ -77,7 +77,7 @@ struct Prune: AsyncParsableCommand { try prunablesToDelete.forEach { try $0.delete() } } - static func reclaimIfNeeded(_ requiredBytes: UInt64) throws { + static func reclaimIfNeeded(_ requiredBytes: UInt64, _ initiator: Prunable? = nil) throws { SentrySDK.configureScope { scope in scope.setContext(value: ["requiredBytes": requiredBytes], key: "Prune") } @@ -114,10 +114,10 @@ struct Prune: AsyncParsableCommand { return } - try Prune.reclaimIfPossible(requiredBytes - volumeAvailableCapacityCalculated) + try Prune.reclaimIfPossible(requiredBytes - volumeAvailableCapacityCalculated, initiator) } - private static func reclaimIfPossible(_ reclaimBytes: UInt64) throws { + private static func reclaimIfPossible(_ reclaimBytes: UInt64, _ initiator: Prunable? = nil) throws { let transaction = SentrySDK.startTransaction(name: "Pruning cache", operation: "prune", bindToScope: true) defer { transaction.finish() } @@ -141,6 +141,11 @@ struct Prune: AsyncParsableCommand { break } + if prunable.url == initiator?.url.resolvingSymlinksInPath() { + // do not prune the initiator + continue + } + try SentrySDK.span?.setData(value: prunable.sizeBytes(), key: prunable.url.path) cacheReclaimedBytes += try prunable.sizeBytes()