Skip to content

Commit 72043f9

Browse files
authored
ContentStore: Fix totalAllocatedSize on Linux (#761)
`.totalFileAllocatedSizeKey` returns nil for directories on Darwin but on Linux it returns `st_blocks * st_blksize` (4 KB each) in Foundation. The empty-store test summed three directory inodes on Linux and failed with `#expect(size == 0)`. This change adds filter on the enumerator to regular files only so the totals are content-only and will work for both Darwin and Linux.
1 parent a2a1add commit 72043f9

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

Sources/ContainerizationOCI/Content/LocalContentStore.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,17 +206,21 @@ public actor LocalContentStore: ContentStore {
206206
guard
207207
let enumerator = fileManager.enumerator(
208208
at: self._basePath,
209-
includingPropertiesForKeys: [.totalFileAllocatedSizeKey],
209+
includingPropertiesForKeys: [.totalFileAllocatedSizeKey, .isRegularFileKey],
210210
options: [.skipsHiddenFiles]
211211
)
212212
else {
213213
throw ContainerizationError(.internalError, message: "failed to enumerate content store at \(self._basePath.path)")
214214
}
215215
var size: UInt64 = 0
216216
for case let fileURL as URL in enumerator {
217-
guard let values = try? fileURL.resourceValues(forKeys: [.totalFileAllocatedSizeKey]),
217+
guard let values = try? fileURL.resourceValues(forKeys: [.totalFileAllocatedSizeKey, .isRegularFileKey]), values.isRegularFile == true,
218218
let fileSize = values.totalFileAllocatedSize
219219
else {
220+
// Skip directories and other non-regular entries. On Linux,
221+
// `.totalFileAllocatedSizeKey` reports block allocation for
222+
// directories, which would otherwise count empty-store
223+
// inode overhead as content.
220224
continue
221225
}
222226
size += UInt64(fileSize)

0 commit comments

Comments
 (0)