mirror of
https://github.com/apple/container.git
synced 2026-07-14 21:47:01 +00:00
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user