Skip to content

Commit a2972aa

Browse files
fkorotkovclaude
andauthored
feat: prioritize pruning of old SHA when pulling updated tags (#1102)
* 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 <[email protected]> * format * Review comments --------- Co-authored-by: Claude <[email protected]>
1 parent 3a6c5fb commit a2972aa

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Table of Contents
2929

3030
1. Code should follow camel case
3131
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:
32+
3233
```bash
3334
swift package plugin --allow-writing-to-package-directory swiftformat --cache ignore .
3435
```

Sources/tart/VMStorageOCI.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ class VMStorageOCI: PrunableStorage {
2727
return digest
2828
}
2929

30-
func open(_ name: RemoteName) throws -> VMDirectory {
30+
func open(_ name: RemoteName, _ accessDate: Date = Date()) throws -> VMDirectory {
3131
let vmDir = VMDirectory(baseURL: vmURL(name))
3232

3333
try vmDir.validate(userFriendlyName: name.description)
3434

35-
try vmDir.baseURL.updateAccessDate()
35+
try vmDir.baseURL.updateAccessDate(accessDate)
3636

3737
return vmDir
3838
}
@@ -180,6 +180,10 @@ class VMStorageOCI: PrunableStorage {
180180
let transaction = SentrySDK.startTransaction(name: name.description, operation: "pull", bindToScope: true)
181181
let tmpVMDir = try VMDirectory.temporaryDeterministic(key: name.description)
182182

183+
// Open an existing VM directory corresponding to this name, if any,
184+
// marking it as outdated to speed up the garbage collection process
185+
_ = try? open(name, Date(timeIntervalSince1970: 0))
186+
183187
// Lock the temporary VM directory to prevent it's garbage collection
184188
let tmpVMDirLock = try FileLock(lockURL: tmpVMDir.baseURL)
185189
try tmpVMDirLock.lock()

0 commit comments

Comments
 (0)