Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Zip.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
303B4F6E1E4CBE5000DC1633 /* permissions.zip in Resources */ = {isa = PBXBuildFile; fileRef = 303B4F6D1E4CBE5000DC1633 /* permissions.zip */; };
305237181E64595700CA46D1 /* unsupported_permissions.zip in Resources */ = {isa = PBXBuildFile; fileRef = 305237171E64595700CA46D1 /* unsupported_permissions.zip */; };
342545901CE525B200336074 /* Zip.swift in Sources */ = {isa = PBXBuildFile; fileRef = 347E3AD71C1E04C900A11FD3 /* Zip.swift */; };
342545921CE525B200336074 /* unzip.c in Sources */ = {isa = PBXBuildFile; fileRef = 342FC0EB1C5044DC0023A3C3 /* unzip.c */; };
342545941CE525B200336074 /* QuickZip.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3443A3F51C4AB8A3004AD173 /* QuickZip.swift */; };
Expand Down Expand Up @@ -71,6 +72,7 @@

/* Begin PBXFileReference section */
303B4F6D1E4CBE5000DC1633 /* permissions.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = permissions.zip; sourceTree = "<group>"; };
305237171E64595700CA46D1 /* unsupported_permissions.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = unsupported_permissions.zip; sourceTree = "<group>"; };
342545B51CE525B200336074 /* Zip.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Zip.framework; sourceTree = BUILT_PRODUCTS_DIR; };
342FC0E71C5044DC0023A3C3 /* crypt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = crypt.h; sourceTree = "<group>"; };
342FC0E81C5044DC0023A3C3 /* ioapi.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ioapi.c; sourceTree = "<group>"; };
Expand Down Expand Up @@ -196,6 +198,7 @@
347E3A821C1DFFB500A11FD3 /* ZipTests */ = {
isa = PBXGroup;
children = (
305237171E64595700CA46D1 /* unsupported_permissions.zip */,
303B4F6D1E4CBE5000DC1633 /* permissions.zip */,
34940A221C58876200D41574 /* 3crBXeO.gif */,
34940A231C58876200D41574 /* kYkLkPf.gif */,
Expand Down Expand Up @@ -418,6 +421,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
305237181E64595700CA46D1 /* unsupported_permissions.zip in Resources */,
303B4F6E1E4CBE5000DC1633 /* permissions.zip in Resources */,
34940A251C58876200D41574 /* kYkLkPf.gif in Resources */,
3443A3FD1C4AD199004AD173 /* bb8.zip in Resources */,
Expand Down
15 changes: 10 additions & 5 deletions Zip/Zip.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,16 @@ public class Zip {
}

//Set file permissions from current fileInfo
let permissions = (fileInfo.external_fa >> 16) & 0x1FF
do {
try fileManager.setAttributes([.posixPermissions : permissions], ofItemAtPath: fullPath)
} catch let error {
print("Failed to set permissions to file \(fullPath)")
if fileInfo.external_fa != 0 {
let permissions = (fileInfo.external_fa >> 16) & 0x1FF
//We will devifne a valid permission range between Owner read only to full access
if permissions >= 0o400 && permissions <= 0o777 {
do {
try fileManager.setAttributes([.posixPermissions : permissions], ofItemAtPath: fullPath)
} catch {
print("Failed to set permissions to file \(fullPath), error: \(error)")
}
}
}

ret = unzGoToNextFile(zip)
Expand Down
18 changes: 18 additions & 0 deletions ZipTests/ZipTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,24 @@ class ZipTests: XCTestCase {
}
}

func testUnzipWithUnsupportedPermissions() {
do {
let permissionsURL = Bundle(for: ZipTests.self).url(forResource: "unsupported_permissions", withExtension: "zip")!
let unzipDestination = try Zip.quickUnzipFile(permissionsURL)
print(unzipDestination)
let fileManager = FileManager.default
let permission644 = unzipDestination.appendingPathComponent("unsupported_permission").appendingPathExtension("txt")
do {
let attributes644 = try fileManager.attributesOfItem(atPath: permission644.path)
XCTAssertEqual(attributes644[.posixPermissions] as? Int, 0o644)
} catch {
XCTFail("Failed to get file attributes \(error)")
}
} catch {
XCTFail("Failed extract unsupported_permissions.zip")
}
}

func testUnzipPermissions() {
do {
let permissionsURL = Bundle(for: ZipTests.self).url(forResource: "permissions", withExtension: "zip")!
Expand Down
Binary file added ZipTests/unsupported_permissions.zip
Binary file not shown.