Merge pull request #400 from ZipArchive/__MACOSX

ignoring __MACOSX/
This commit is contained in:
Antoine Cœur
2017-10-10 20:09:20 -05:00
committed by GitHub
2 changed files with 13 additions and 8 deletions
@@ -240,10 +240,8 @@
NSString *outputPath = [self _cachesPath:@"IncorrectHeaders"];
id<SSZipArchiveDelegate> delegate = [ProgressDelegate new];
__unused BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:delegate];
// Temp disabled test, it's unclear if it's supposed to be a success of failure
// as Z_BUF_ERROR is returned for "__MACOSX/IncorrectHeaders/._Readme.txt"
//XCTAssertTrue(success);
BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:delegate];
XCTAssertTrue(success);
NSString *intendedReadmeTxtMD5 = @"31ac96301302eb388070c827447290b5";
+11 -4
View File
@@ -295,9 +295,10 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
[delegate zipArchiveProgressEvent:currentPosition total:fileSize];
}
NSInteger currentFileNumber = 0;
NSInteger currentFileNumber = -1;
NSError *unzippingError;
do {
currentFileNumber++;
if (ret == UNZ_END_OF_LIST_OF_FILE)
break;
@autoreleasepool {
@@ -331,7 +332,8 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
if ([delegate respondsToSelector:@selector(zipArchiveShouldUnzipFileAtIndex:totalFiles:archivePath:fileInfo:)]) {
if (![delegate zipArchiveShouldUnzipFileAtIndex:currentFileNumber
totalFiles:(NSInteger)globalInfo.number_entry
archivePath:path fileInfo:fileInfo]) {
archivePath:path
fileInfo:fileInfo]) {
success = NO;
canceled = YES;
break;
@@ -358,6 +360,12 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
BOOL fileIsSymbolicLink = _fileIsSymbolicLink(&fileInfo);
NSString * strPath = [SSZipArchive _filenameStringWithCString:filename size:fileInfo.size_filename];
if ([strPath hasPrefix:@"__MACOSX/"]) {
// ignoring resource forks: https://superuser.com/questions/104500/what-is-macosx-folder
unzCloseCurrentFile(zip);
ret = unzGoToNextFile(zip);
continue;
}
if (!strPath.length) {
// if filename data is unsalvageable, we default to currentFileNumber
strPath = @(currentFileNumber).stringValue;
@@ -555,7 +563,7 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
crc_ret = unzCloseCurrentFile(zip);
if (crc_ret == UNZ_CRCERROR) {
//CRC ERROR
// CRC ERROR
success = NO;
break;
}
@@ -570,7 +578,6 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
archivePath:path unzippedFilePath: fullPath];
}
currentFileNumber++;
if (progressHandler)
{
progressHandler(strPath, fileInfo, currentFileNumber, globalInfo.number_entry);