From a2972aa4d92a568707bf10e1852b0095e02a3759 Mon Sep 17 00:00:00 2001 From: Fedor Korotkov Date: Mon, 7 Jul 2025 01:52:05 -0700 Subject: [PATCH] feat: prioritize pruning of old SHA when pulling updated tags (#1102) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: prioritize pruning of old SHA when pulling updated tags When pulling a new version of a tagged image (e.g., ghcr.io/cirruslabs/macos-runner:sonoma), set the access date of the previous SHA to epoch time (1970-01-01). This ensures that the old SHA will be prioritized for pruning, even if it was accessed more recently than other cached images. This helps manage disk space more efficiently by automatically cleaning up superseded versions of frequently-updated tagged images. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude * format * Review comments --------- Co-authored-by: Claude --- CONTRIBUTING.md | 1 + Sources/tart/VMStorageOCI.swift | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 63ed874..021b6e0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -29,6 +29,7 @@ Table of Contents 1. Code should follow camel case 2. Code should follow [SwiftFormat](https://github.com/nicklockwood/SwiftFormat#swift-package-manager-plugin) guidelines. You can auto-format the code by running the following command: + ```bash swift package plugin --allow-writing-to-package-directory swiftformat --cache ignore . ``` diff --git a/Sources/tart/VMStorageOCI.swift b/Sources/tart/VMStorageOCI.swift index 5cd51f7..f71c547 100644 --- a/Sources/tart/VMStorageOCI.swift +++ b/Sources/tart/VMStorageOCI.swift @@ -27,12 +27,12 @@ class VMStorageOCI: PrunableStorage { return digest } - func open(_ name: RemoteName) throws -> VMDirectory { + func open(_ name: RemoteName, _ accessDate: Date = Date()) throws -> VMDirectory { let vmDir = VMDirectory(baseURL: vmURL(name)) try vmDir.validate(userFriendlyName: name.description) - try vmDir.baseURL.updateAccessDate() + try vmDir.baseURL.updateAccessDate(accessDate) return vmDir } @@ -180,6 +180,10 @@ class VMStorageOCI: PrunableStorage { let transaction = SentrySDK.startTransaction(name: name.description, operation: "pull", bindToScope: true) let tmpVMDir = try VMDirectory.temporaryDeterministic(key: name.description) + // Open an existing VM directory corresponding to this name, if any, + // marking it as outdated to speed up the garbage collection process + _ = try? open(name, Date(timeIntervalSince1970: 0)) + // Lock the temporary VM directory to prevent it's garbage collection let tmpVMDirLock = try FileLock(lockURL: tmpVMDir.baseURL) try tmpVMDirLock.lock()