diff --git a/Sources/Containerization/Image/ImageStore/ImageStore+Export.swift b/Sources/Containerization/Image/ImageStore/ImageStore+Export.swift index 7fa1eadd..75678c2a 100644 --- a/Sources/Containerization/Image/ImageStore/ImageStore+Export.swift +++ b/Sources/Containerization/Image/ImageStore/ImageStore+Export.swift @@ -91,14 +91,14 @@ extension ImageStore { for layerGroup in pushQueue { for desc in layerGroup { await progress?([ - ProgressEvent(event: "add-total-size", value: desc.size), - ProgressEvent(event: "add-total-items", value: 1), + ProgressEvent(.addTotalSize(desc.size)), + ProgressEvent(.addTotalItems(1)), ]) } } await progress?([ - ProgressEvent(event: "add-total-size", value: localIndexData.count), - ProgressEvent(event: "add-total-items", value: 1), + ProgressEvent(.addTotalSize(Int64(localIndexData.count))), + ProgressEvent(.addTotalItems(1)), ]) } @@ -135,15 +135,15 @@ extension ImageStore { } try await client.push(name: name, ref: tag, descriptor: descriptor, streamGenerator: generator, progress: progress) await progress?([ - ProgressEvent(event: "add-size", value: descriptor.size), - ProgressEvent(event: "add-items", value: 1), + ProgressEvent(.addSize(descriptor.size)), + ProgressEvent(.addItems(1)), ]) } catch let err as ContainerizationError { guard err.code != .exists else { // We reported the total items and size and have to account for them in existing content. await progress?([ - ProgressEvent(event: "add-size", value: descriptor.size), - ProgressEvent(event: "add-items", value: 1), + ProgressEvent(.addSize(descriptor.size)), + ProgressEvent(.addItems(1)), ]) return } diff --git a/Sources/Containerization/Image/ImageStore/ImageStore+Import.swift b/Sources/Containerization/Image/ImageStore/ImageStore+Import.swift index 9adcf6ff..afb98508 100644 --- a/Sources/Containerization/Image/ImageStore/ImageStore+Import.swift +++ b/Sources/Containerization/Image/ImageStore/ImageStore+Import.swift @@ -52,8 +52,8 @@ extension ImageStore { size += desc.size } await progress([ - ProgressEvent(event: "add-total-size", value: size), - ProgressEvent(event: "add-total-items", value: toProcess.count), + ProgressEvent(.addTotalSize(size)), + ProgressEvent(.addTotalItems(toProcess.count)), ]) } @@ -146,9 +146,9 @@ extension ImageStore { try FileManager.default.copyItem(at: found.path, to: ingestDir.appendingPathComponent(descriptor.digest.trimmingDigestPrefix)) await progress?([ // Count the size of the blob - ProgressEvent(event: "add-size", value: descriptor.size), + ProgressEvent(.addSize(descriptor.size)), // Count the number of blobs - ProgressEvent(event: "add-items", value: 1), + ProgressEvent(.addItems(1)), ]) return } @@ -160,7 +160,7 @@ extension ImageStore { } // Count the number of blobs await progress?([ - ProgressEvent(event: "add-items", value: 1) + ProgressEvent(.addItems(1)) ]) } @@ -190,7 +190,7 @@ extension ImageStore { if let progress { let size = Int64(result.size) await progress([ - ProgressEvent(event: "add-size", value: size) + ProgressEvent(.addSize(size)) ]) } guard result.digest.digestString == descriptor.digest else { diff --git a/Sources/ContainerizationEXT4/Formatter+Unpack.swift b/Sources/ContainerizationEXT4/Formatter+Unpack.swift index fee04cc3..d97f3689 100644 --- a/Sources/ContainerizationEXT4/Formatter+Unpack.swift +++ b/Sources/ContainerizationEXT4/Formatter+Unpack.swift @@ -44,7 +44,7 @@ extension EXT4.Formatter { if let progress { Task { await progress([ - ProgressEvent(event: "add-items", value: 1) + ProgressEvent(.addItems(1)) ]) } } @@ -88,7 +88,7 @@ extension EXT4.Formatter { if let progress, let size = entry.size { Task { await progress([ - ProgressEvent(event: "add-size", value: Int64(size)) + ProgressEvent(.addSize(Int64(size))) ]) } } diff --git a/Sources/ContainerizationExtras/ProgressEvent.swift b/Sources/ContainerizationExtras/ProgressEvent.swift index 3210aa93..8ac03822 100644 --- a/Sources/ContainerizationExtras/ProgressEvent.swift +++ b/Sources/ContainerizationExtras/ProgressEvent.swift @@ -14,6 +14,14 @@ // limitations under the License. //===----------------------------------------------------------------------===// +/// The kind of a progress update event. +public enum ProgressEventKind: Sendable { + case addItems(Int) + case addTotalItems(Int) + case addSize(Int64) + case addTotalSize(Int64) +} + /// A progress update event. public struct ProgressEvent: Sendable { /// The event name. The possible values: @@ -25,13 +33,21 @@ public struct ProgressEvent: Sendable { /// The event value. public let value: any Sendable - /// Creates an instance. - /// - Parameters: - /// - event: The event name. - /// - value: The event value. - public init(event: String, value: any Sendable) { - self.event = event - self.value = value + public init(_ kind: ProgressEventKind) { + switch kind { + case .addItems(let value): + event = "add-items" + self.value = value + case .addTotalItems(let value): + event = "add-total-items" + self.value = value + case .addSize(let value): + event = "add-size" + self.value = value + case .addTotalSize(let value): + event = "add-total-size" + self.value = value + } } } diff --git a/Sources/ContainerizationOCI/Client/LocalOCILayoutClient.swift b/Sources/ContainerizationOCI/Client/LocalOCILayoutClient.swift index 80632668..44bae971 100644 --- a/Sources/ContainerizationOCI/Client/LocalOCILayoutClient.swift +++ b/Sources/ContainerizationOCI/Client/LocalOCILayoutClient.swift @@ -71,7 +71,7 @@ package final class LocalOCILayoutClient: ContentClient { if let progress, let fileSize = fileManager.fileSize(atPath: filePath) { await progress([ - ProgressEvent(event: "add-size", value: fileSize) + ProgressEvent(.addSize(fileSize)) ]) } } catch let error as NSError { @@ -93,7 +93,7 @@ package final class LocalOCILayoutClient: ContentClient { if let progress, let fileSize = fileManager.fileSize(atPath: filePath) { await progress([ - ProgressEvent(event: "add-size", value: fileSize) + ProgressEvent(.addSize(fileSize)) ]) } } catch { diff --git a/Sources/ContainerizationOCI/Client/RegistryClient+Fetch.swift b/Sources/ContainerizationOCI/Client/RegistryClient+Fetch.swift index 3990a9eb..f715cb33 100644 --- a/Sources/ContainerizationOCI/Client/RegistryClient+Fetch.swift +++ b/Sources/ContainerizationOCI/Client/RegistryClient+Fetch.swift @@ -181,7 +181,7 @@ extension RegistryClient { received += readBytes let written = try await writer.write(contentsOf: buf) await progress?([ - ProgressEvent(event: "add-size", value: written) + ProgressEvent(.addSize(written)) ]) guard written == readBytes else { throw ContainerizationError( @@ -224,7 +224,7 @@ extension RegistryClient { let readBytes = Int64(buf.readableBytes) received += readBytes await progress?([ - ProgressEvent(event: "add-size", value: readBytes) + ProgressEvent(.addSize(readBytes)) ]) try fd.write(contentsOf: buf.readableBytesView) hasher.update(data: buf.readableBytesView)