Skip to content
Merged
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
34 changes: 31 additions & 3 deletions Sources/ContainerClient/Archiver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,25 @@ import Foundation

public final class Archiver: Sendable {
public struct ArchiveEntryInfo: Sendable {
let pathOnHost: URL
let pathInArchive: URL
public let pathOnHost: URL
public let pathInArchive: URL

public init(pathOnHost: URL, pathInArchive: URL) {
public let owner: UInt32?
public let group: UInt32?
public let permissions: UInt16?

public init(
pathOnHost: URL,
pathInArchive: URL,
owner: UInt32? = nil,
group: UInt32? = nil,
permissions: UInt16? = nil
) {
self.pathOnHost = pathOnHost
self.pathInArchive = pathInArchive
self.owner = owner
self.group = group
self.permissions = permissions
}
}

Expand Down Expand Up @@ -246,6 +259,21 @@ public final class Archiver: Sendable {
entry.modificationDate = modificationDate
}

// Apply explicit overrides from ArchiveEntryInfo when provided
if let overrideOwner = entryInfo.owner {
entry.owner = overrideOwner
}
if let overrideGroup = entryInfo.group {
entry.group = overrideGroup
}
if let overridePerm = entryInfo.permissions {
#if os(macOS)
entry.permissions = overridePerm
#else
entry.permissions = UInt32(overridePerm)
#endif
}

let pathTrimmed = Self._trimPathPrefix(entryInfo.pathInArchive.relativePath, pathPrefix: pathPrefix)
entry.path = pathTrimmed
return entry
Expand Down
36 changes: 34 additions & 2 deletions Sources/NativeBuilder/ContainerBuildDemo/Demo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,44 @@ import ContainerBuildReporting
import ContainerBuildSnapshotter
import Foundation

public actor DummySnapshotter: Snapshotter {
public init() {}

public func prepare(_ snapshot: Snapshot) async throws -> Snapshot {
if let mount = snapshot.state.mountpoint {
var isDir: ObjCBool = false
if !FileManager.default.fileExists(atPath: mount.path, isDirectory: &isDir) {
try FileManager.default.createDirectory(at: mount, withIntermediateDirectories: true)
}
}
return snapshot
}

public func commit(_ snapshot: Snapshot) async throws -> Snapshot {
// Produce a minimal committed snapshot; layer fields are optional
Snapshot(
id: snapshot.id,
digest: snapshot.digest,
size: snapshot.size,
parent: snapshot.parent,
createdAt: snapshot.createdAt,
state: .committed()
)
}

public func remove(_ snapshot: Snapshot) async throws {
if let mount = snapshot.state.mountpoint {
try? FileManager.default.removeItem(at: mount)
}
}
}

/// A simple demonstration of the build execution system.
public struct Demo {
public static func runDemo() async throws {
// Set up the build environment first
let snapshotter = MemorySnapshotter()
let cache = MemoryBuildCache()
let snapshotter = DummySnapshotter()
let cache = NoOpBuildCache()
let reporter = Reporter()

// Create a build graph with parallel operations, passing the reporter
Expand Down
Loading