Skip to content

Commit c3fe889

Browse files
authored
Fix for decompressing zstd with localpath URL. (#512)
- InputSource(url:) rejects URLs with nil scheme, which was what was passed when running the `container system kernel set` integration test with a local kernel archive path.
1 parent 258ad89 commit c3fe889

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Sources/ContainerizationArchive/ArchiveReader.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ public final class ArchiveReader {
103103
/// Initialize the `ArchiveReader` to read from a specified file URL
104104
/// by trying to auto determine the archives `Format` and `Filter`.
105105
public init(file: URL) throws {
106-
107106
self.underlying = archive_read_new()
108107

109108
// Try to decompress as zstd first, fall back to original if it fails
@@ -128,7 +127,15 @@ public final class ArchiveReader {
128127

129128
/// Decompress a zstd file to a temporary location
130129
private static func decompressZstd(_ source: URL) throws -> URL {
131-
guard let inputStream = InputStream(url: source) else {
130+
let inputStream: InputStream?
131+
if source.scheme == nil || source.scheme == "" {
132+
// can't use InputStream(url:) with nil scheme
133+
inputStream = .init(fileAtPath: source.path)
134+
} else {
135+
inputStream = InputStream(url: source)
136+
}
137+
138+
guard let inputStream else {
132139
throw ArchiveError.noUnderlyingArchive
133140
}
134141
inputStream.open()

0 commit comments

Comments
 (0)