From 2d60b339fcf2d3eb38ef229fd2125899dda97fc7 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Mon, 23 Jul 2018 09:27:39 +0300 Subject: [PATCH] [TAR] Add correctly set format property to TarEntryInfo --- Sources/TAR/TarEntryInfo.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sources/TAR/TarEntryInfo.swift b/Sources/TAR/TarEntryInfo.swift index 9d140b39..18d735fc 100644 --- a/Sources/TAR/TarEntryInfo.swift +++ b/Sources/TAR/TarEntryInfo.swift @@ -91,6 +91,7 @@ public struct TarEntryInfo: ContainerEntryInfo { public let unknownExtendedHeaderRecords: [String: String]? let specialEntryType: SpecialEntryType? + let format: TarContainer.Format let hasRecognizedMagic: Bool let blockStartIndex: Int @@ -208,6 +209,16 @@ public struct TarEntryInfo: ContainerEntryInfo { self.deviceMinorNumber = nil } + if local != nil || global != nil { + self.format = .pax + } else if magic == 0x00_20_20_72_61_74_73_75 || longName != nil || longLinkName != nil { + self.format = .gnu + } else if magic == 0x3030007261747375 || magic == 0x3030207261747375 { + self.format = .ustar + } else { + self.format = .prePosix + } + // Set `name` and `linkName` to values from PAX or GNU format if possible. self.name = ((local?.path ?? global?.path) ?? longName) ?? name self.linkName = ((local?.linkpath ?? global?.linkpath) ?? longLinkName) ?? linkName