Skip to content
Merged
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
15 changes: 10 additions & 5 deletions Sources/ContainerCommands/Image/ImageSave.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import Containerization
import ContainerizationError
import ContainerizationOCI
import Foundation
import SystemPackage
import TerminalProgress

extension Application {
Expand All @@ -47,9 +48,13 @@ extension Application {
@Option(
name: .shortAndLong, help: "Pathname for the saved image", completion: .file(),
transform: { str in
URL(fileURLWithPath: str, relativeTo: .currentDirectory()).absoluteURL.path(percentEncoded: false)
let path = FilePath(str)
guard path.isRelative else { return path.lexicallyNormalized() }
return FilePath(FileManager.default.currentDirectoryPath)
.pushing(path)
.lexicallyNormalized()
})
var output: String?
var output: FilePath?

@Option(
help: "Platform for the saved image (format: os/arch[/variant], takes precedence over --os and --arch) [environment: CONTAINER_DEFAULT_PLATFORM]"
Expand Down Expand Up @@ -109,7 +114,9 @@ extension Application {
}

// Write to stdout; otherwise write to the output file
if output == nil {
if let output {
try await ClientImage.save(references: references, out: output.string, platform: p, containerSystemConfig: containerSystemConfig)
} else {
let tempFile = FileManager.default.temporaryDirectory.appendingPathComponent("\(UUID().uuidString).tar")
defer {
try? FileManager.default.removeItem(at: tempFile)
Expand All @@ -132,8 +139,6 @@ extension Application {
FileHandle.standardOutput.write(chunk)
}
try fileHandle.close()
} else {
try await ClientImage.save(references: references, out: output!, platform: p, containerSystemConfig: containerSystemConfig)
}

progress.finish()
Expand Down