Skip to content

Commit 860139b

Browse files
authored
Fix ImageStore.prune() behavior to actually remove images (#420)
- Fixes #417. Rename `_prune()` to `cleanupOrphanedBlobs()` to clarify what it actually does, and remove `prune()` method as we'll do all that logic in container directly.
1 parent 14f56e4 commit 860139b

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

Sources/Containerization/Image/ImageStore/ImageStore.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,33 +124,32 @@ extension ImageStore {
124124
try await self.lock.withLock { lockCtx in
125125
try await self.referenceManager.delete(reference: reference)
126126
if performCleanup {
127-
try await self._prune(lockCtx)
127+
try await self._cleanupOrphanedBlobs(lockCtx)
128128
}
129129
}
130130
}
131131

132-
/// Perform a garbage collection in the underlying `ContentStore` that is managed by the `ImageStore`.
132+
/// Clean up orphaned blobs that are no longer referenced by any image.
133133
///
134134
/// - Returns: Returns a tuple of `(deleted, freed)`.
135135
/// `deleted` : A list of the names of the content items that were deleted from the `ContentStore`,
136136
/// `freed` : The total size of the items that were deleted.
137137
@discardableResult
138-
public func prune() async throws -> (deleted: [String], freed: UInt64) {
138+
public func cleanupOrphanedBlobs() async throws -> (deleted: [String], freed: UInt64) {
139139
try await self.lock.withLock { lockCtx in
140-
try await self._prune(lockCtx)
140+
try await self._cleanupOrphanedBlobs(lockCtx)
141141
}
142142
}
143143

144144
@discardableResult
145-
private func _prune(_ lock: AsyncLock.Context) async throws -> ([String], UInt64) {
145+
private func _cleanupOrphanedBlobs(_ lock: AsyncLock.Context) async throws -> (deleted: [String], freed: UInt64) {
146146
let images = try await self.list()
147147
var referenced: [String] = []
148148
for image in images {
149149
try await referenced.append(contentsOf: image.referencedDigests().uniqued())
150150
}
151151
let (deleted, size) = try await self.contentStore.delete(keeping: referenced)
152152
return (deleted, size)
153-
154153
}
155154

156155
/// Tag an existing image such that it can be referenced by another name.

0 commit comments

Comments
 (0)