diff --git a/Sources/ContainerCommands/Image/ImageSave.swift b/Sources/ContainerCommands/Image/ImageSave.swift index a3942a6c..d1cab796 100644 --- a/Sources/ContainerCommands/Image/ImageSave.swift +++ b/Sources/ContainerCommands/Image/ImageSave.swift @@ -23,6 +23,7 @@ import Containerization import ContainerizationError import ContainerizationOCI import Foundation +import SystemPackage import TerminalProgress extension Application { @@ -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]" @@ -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) @@ -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()