Skip to content

Commit aed747b

Browse files
committed
remove logic for calculating disk space freed
1 parent 474d9e0 commit aed747b

File tree

5 files changed

+10
-63
lines changed

5 files changed

+10
-63
lines changed

Sources/ContainerClient/Core/ClientNetwork.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,16 @@ extension ClientNetwork {
8888
}
8989

9090
/// Prune the network with the given id.
91-
public static func prune() async throws -> ([String], UInt64) {
91+
public static func prune() async throws -> [String] {
9292
let client = XPCClient(service: serviceIdentifier)
9393
let message = XPCMessage(route: .networkPrune)
9494
let reply = try await client.send(message)
9595

9696
guard let responseData = reply.dataNoCopy(key: .networkId) else {
97-
return ([], 0)
97+
return []
9898
}
9999

100100
let networkNames = try JSONDecoder().decode([String].self, from: responseData)
101-
let size = reply.uint64(key: .size)
102-
return (networkNames, size)
101+
return networkNames
103102
}
104103
}

Sources/ContainerCommands/Network/NetworkPrune.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,11 @@ extension Application.NetworkCommand {
3030
var global: Flags.Global
3131

3232
public func run() async throws {
33-
let (networkNames, size) = try await ClientNetwork.prune()
34-
let formatter = ByteCountFormatter()
35-
let freed = formatter.string(fromByteCount: Int64(size))
33+
let networkNames = try await ClientNetwork.prune()
3634

3735
for name in networkNames {
3836
print(name)
3937
}
40-
print("Reclaimed \(freed) in disk space")
4138
}
4239
}
4340
}

Sources/Services/ContainerAPIService/Networks/NetworksHarness.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,11 @@ public struct NetworksHarness: Sendable {
7070

7171
@Sendable
7272
public func prune(_ message: XPCMessage) async throws -> XPCMessage {
73-
let (networkNames, size) = try await service.prune()
73+
let networkNames = try await service.prune()
7474
let data = try JSONEncoder().encode(networkNames)
7575

7676
let reply = message.reply()
7777
reply.set(key: .networkId, value: data)
78-
reply.set(key: .size, value: size)
7978
return reply
8079
}
8180
}

Sources/Services/ContainerAPIService/Networks/NetworksService.swift

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public actor NetworksService {
247247
}
248248

249249
/// Prune all networks with no container connections (preserve default/system networks)
250-
public func prune() async throws -> ([String], UInt64) {
250+
public func prune() async throws -> [String] {
251251
let allNetworks = try await self.store.list()
252252
// do entire prune operation atomically with container list
253253
return try await self.containersService.withContainerList { containers in
@@ -263,27 +263,20 @@ public actor NetworksService {
263263
}
264264

265265
var prunedNames = [String]()
266-
var totalSize: UInt64 = 0
267266

268267
for network in networksToPrune {
269268
do {
270-
// calculate actual disk usage before deletion
271-
let networkPath = self.networkPath(for: network.id)
272-
let actualSize = self.calculateDirectorySize(at: networkPath)
273-
274269
try await self.store.delete(network.id)
275270
await self.removeNetworkState(for: network.id)
276-
try self.removeNetworkDirectory(for: network.id)
277271

278272
prunedNames.append(network.id)
279-
totalSize += actualSize
280-
self.log.info("Pruned network", metadata: ["name": "\(network.id)", "size": "\(actualSize)"])
273+
self.log.info("Pruned network", metadata: ["name": "\(network.id)"])
281274
} catch {
282275
self.log.error("Failed to prune network \(network.id): \(error)")
283276
}
284277
}
285278

286-
return (prunedNames, totalSize)
279+
return prunedNames
287280
}
288281
}
289282

@@ -341,44 +334,4 @@ public actor NetworksService {
341334
private func removeNetworkState(for id: String) {
342335
networkStates.removeValue(forKey: id)
343336
}
344-
345-
private nonisolated func networkPath(for name: String) -> String {
346-
resourceRoot.appendingPathComponent(name).path
347-
}
348-
349-
private nonisolated func removeNetworkDirectory(for name: String) throws {
350-
let networkPath = networkPath(for: name)
351-
let fm = FileManager.default
352-
353-
if fm.fileExists(atPath: networkPath) {
354-
try fm.removeItem(atPath: networkPath)
355-
}
356-
}
357-
358-
private nonisolated func calculateDirectorySize(at path: String) -> UInt64 {
359-
let url = URL(fileURLWithPath: path)
360-
let fileManager = FileManager.default
361-
362-
guard
363-
let enumerator = fileManager.enumerator(
364-
at: url,
365-
includingPropertiesForKeys: [.totalFileAllocatedSizeKey],
366-
options: [.skipsHiddenFiles]
367-
)
368-
else {
369-
return 0
370-
}
371-
372-
var totalSize: UInt64 = 0
373-
for case let fileURL as URL in enumerator {
374-
guard let resourceValues = try? fileURL.resourceValues(forKeys: [.totalFileAllocatedSizeKey]),
375-
let fileSize = resourceValues.totalFileAllocatedSize
376-
else {
377-
continue
378-
}
379-
totalSize += UInt64(fileSize)
380-
}
381-
382-
return totalSize
383-
}
384337
}

Tests/CLITests/Subcommands/Networks/TestCLINetwork.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,15 @@ class TestCLINetwork: CLITest {
208208
// Clean up is necessary for testing prune with no networks
209209
doNetworkDeleteIfExists(name: "testnetworkcreateanduse")
210210

211-
// Prune with no networks should succeed with 0 reclaimed
211+
// Prune with no networks should succeed
212212
let (_, _, _, statusBefore) = try run(arguments: ["network", "list", "--quiet"])
213213
#expect(statusBefore == 0)
214214
let (_, output, error, status) = try run(arguments: ["network", "prune"])
215215
if status != 0 {
216216
throw CLIError.executionFailed("network prune failed: \(error)")
217217
}
218218

219-
#expect(output.contains("Zero KB"), "should show no space reclaimed")
219+
#expect(output.isEmpty, "should show no networks pruned")
220220
}
221221

222222
@Test func testNetworkPruneUnusedNetworks() throws {
@@ -250,7 +250,6 @@ class TestCLINetwork: CLITest {
250250

251251
#expect(output.contains(network1), "should prune network1")
252252
#expect(output.contains(network2), "should prune network2")
253-
#expect(output.contains("Reclaimed"), "should show reclaimed space")
254253

255254
// Verify networks are gone
256255
let (_, listAfter, _, statusAfter) = try run(arguments: ["network", "list", "--quiet"])

0 commit comments

Comments
 (0)