Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Sources/Plugins/CoreImages/ImagesHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import ContainerXPC
import Containerization
import Foundation
import Logging
import SystemPackage

@main
struct ImagesHelper: AsyncParsableCommand {
Expand Down Expand Up @@ -113,7 +114,7 @@ extension ImagesHelper {
}

private func initializeContentService(root: URL, log: Logger, routes: inout [String: XPCServer.RouteHandler]) throws {
let service = try ContentStoreService(root: root, log: log)
let service = try ContentStoreService(root: FilePath(root.path(percentEncoded: false)), log: log)
let harness = ContentServiceHarness(service: service, log: log)

routes[ImagesServiceXPCRoute.contentClean.rawValue] = XPCServer.route(harness.clean)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import ContainerizationError
import Foundation
import ContainerizationOCI
import ContainerXPC
import SystemPackage

public struct RemoteContentStoreClient: ContentStore {
private static let serviceIdentifier = "com.apple.container.core.container-core-images"
Expand All @@ -31,7 +32,7 @@ public struct RemoteContentStoreClient: ContentStore {

public init() {}

private func _get(digest: String) async throws -> URL? {
private func _get(digest: String) async throws -> FilePath? {
let client = Self.newClient()
let request = XPCMessage(route: .contentGet)
request.set(key: .digest, value: digest)
Expand All @@ -40,7 +41,7 @@ public struct RemoteContentStoreClient: ContentStore {
guard let path = response.string(key: .contentPath) else {
return nil
}
return URL(filePath: path)
return FilePath(path)
} catch let error as ContainerizationError {
if error.code == .notFound {
return nil
Expand All @@ -50,10 +51,11 @@ public struct RemoteContentStoreClient: ContentStore {
}

public func get(digest: String) async throws -> Content? {
guard let url = try await self._get(digest: digest) else {
guard let path = try await self._get(digest: digest) else {
return nil
}
return try LocalContent(path: url)
// LocalContent is defined upstream in Containerization and only accepts URL.
return try LocalContent(path: URL(filePath: path.string))
}

public func get<T: Decodable>(digest: String) async throws -> T? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public struct ContentServiceHarness: Sendable {
return reply
}
let reply = message.reply()
reply.set(key: .contentPath, value: path.path(percentEncoded: false))
reply.set(key: .contentPath, value: path.string)
return reply
}

Expand Down Expand Up @@ -83,7 +83,7 @@ public struct ContentServiceHarness: Sendable {
let id = session.id
let dir = session.ingestDir
let reply = message.reply()
reply.set(key: .directory, value: dir.path(percentEncoded: false))
reply.set(key: .directory, value: dir.string)
reply.set(key: .ingestSessionId, value: id)
return reply
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,22 @@ import Containerization
import ContainerizationOCI
import Foundation
import Logging
import SystemPackage

public actor ContentStoreService {
private let log: Logger
private let contentStore: LocalContentStore
private let root: URL
private let root: FilePath

public init(root: URL, log: Logger) throws {
try FileManager.default.createDirectory(at: root, withIntermediateDirectories: true)
self.root = root.appendingPathComponent("content")
self.contentStore = try LocalContentStore(path: self.root)
public init(root: FilePath, log: Logger) throws {
try FileManager.default.createDirectory(atPath: root.string, withIntermediateDirectories: true)
self.root = root.appending("content")
// LocalContentStore is defined upstream in Containerization and only accepts URL.
self.contentStore = try LocalContentStore(path: URL(filePath: self.root.string))
self.log = log
}

public func get(digest: String) async throws -> URL? {
public func get(digest: String) async throws -> FilePath? {
self.log.trace(
"ContentStoreService: enter",
metadata: [
Expand All @@ -50,7 +52,10 @@ public actor ContentStoreService {
)
}

return try await self.contentStore.get(digest: digest)?.path
guard let url = try await self.contentStore.get(digest: digest)?.path else {
return nil
}
return FilePath(url.path(percentEncoded: false))
}

@discardableResult
Expand Down Expand Up @@ -97,7 +102,7 @@ public actor ContentStoreService {
return try await self.contentStore.delete(keeping: keeping)
}

public func newIngestSession() async throws -> (id: String, ingestDir: URL) {
public func newIngestSession() async throws -> (id: String, ingestDir: FilePath) {
self.log.debug(
"ContentStoreService: enter",
metadata: [
Expand All @@ -112,7 +117,8 @@ public actor ContentStoreService {
]
)
}
return try await self.contentStore.newIngestSession()
let session = try await self.contentStore.newIngestSession()
return (session.id, FilePath(session.ingestDir.path(percentEncoded: false)))
}

public func completeIngestSession(_ id: String) async throws -> [String] {
Expand Down