From 97566f3e2a10f0e2076e2bfcd49cf965523dfb06 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Tue, 30 May 2017 21:19:16 +0300 Subject: [PATCH] Added reliable way for finding out if an entry is a directory for ms-dos and unix container creator's systems. --- Sources/ZipContainer.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Sources/ZipContainer.swift b/Sources/ZipContainer.swift index 7a4a7305..e5ed551f 100644 --- a/Sources/ZipContainer.swift +++ b/Sources/ZipContainer.swift @@ -81,7 +81,14 @@ public class ZipEntry: ContainerEntry { Particularly, it is true if size of data is 0 and last character of entry's name is '/'. */ public var isDirectory: Bool { - return self.size == 0 && self.name.characters.last == "/" + let hostSystem = (cdEntry.versionMadeBy & 0xFF00) >> 8 + if hostSystem == 0 || hostSystem == 3 { // MS-DOS or UNIX case. + // In both of this cases external file attributes indicate if this is a directory. + // This is indicated by a special bit in the lowest byte of attributes. + return cdEntry.externalFileAttributes & 0x10 != 0 + } else { + return size == 0 && name.characters.last == "/" + } } /**