Removes unused Archiver.uncompress(). (#1372)

- Nothing uses this function, and it does not perform secure extraction.
  Clients should instead use the `ArchiveReader` from the
  ContainerizationArchive library.
This commit is contained in:
J Logan
2026-03-31 14:48:31 -07:00
committed by GitHub
parent d9b8a8d197
commit 2692c5cff4
@@ -108,93 +108,6 @@ public final class Archiver: Sendable {
return hasher.finalize()
}
public static func uncompress(source: URL, destination: URL) throws {
let source = source.standardizedFileURL
let destination = destination.standardizedFileURL
// TODO: ArchiveReader needs some enhancement to support buffered uncompression
let reader = try ArchiveReader(
format: .paxRestricted,
filter: .gzip,
file: source
)
for (entry, data) in reader {
guard let path = entry.path else {
continue
}
let uncompressPath = destination.appendingPathComponent(path)
let fileManager = FileManager.default
switch entry.fileType {
case .blockSpecial, .characterSpecial, .socket:
continue
case .directory:
try fileManager.createDirectory(
at: uncompressPath,
withIntermediateDirectories: true,
attributes: [
FileAttributeKey.posixPermissions: entry.permissions
]
)
case .regular:
try fileManager.createDirectory(
at: uncompressPath.deletingLastPathComponent(),
withIntermediateDirectories: true,
attributes: [
FileAttributeKey.posixPermissions: 0o755
]
)
let success = fileManager.createFile(
atPath: uncompressPath.path,
contents: data,
attributes: [
FileAttributeKey.posixPermissions: entry.permissions
]
)
if !success {
throw POSIXError.fromErrno()
}
try data.write(to: uncompressPath)
case .symbolicLink:
guard let target = entry.symlinkTarget else {
continue
}
try fileManager.createDirectory(
at: uncompressPath.deletingLastPathComponent(),
withIntermediateDirectories: true,
attributes: [
FileAttributeKey.posixPermissions: 0o755
]
)
try fileManager.createSymbolicLink(atPath: uncompressPath.path, withDestinationPath: target)
continue
default:
continue
}
// FIXME: uid/gid for compress.
try fileManager.setAttributes(
[.posixPermissions: NSNumber(value: entry.permissions)],
ofItemAtPath: uncompressPath.path
)
if let creationDate = entry.creationDate {
try fileManager.setAttributes(
[.creationDate: creationDate],
ofItemAtPath: uncompressPath.path
)
}
if let modificationDate = entry.modificationDate {
try fileManager.setAttributes(
[.modificationDate: modificationDate],
ofItemAtPath: uncompressPath.path
)
}
}
}
// MARK: private functions
private static func _compressFile(item: URL, entry: WriteEntry, archiver: ArchiveWriter, hasher: inout SHA256) throws {
guard let stream = InputStream(url: item) else {