Looking into the symbolic link issue.

http://www.pkware.com/documents/casestudies/APPNOTE.TXT
This commit is contained in:
Julius Parishy
2012-05-09 08:18:19 -04:00
parent b6f7f605fe
commit bfc0904d14
5 changed files with 44 additions and 5 deletions
+20 -1
View File
@@ -105,10 +105,27 @@
[delegate zipArchiveWillUnzipFileAtIndex:currentFileNumber totalFiles:(NSInteger)globalInfo.number_entry
archivePath:path fileInfo:fileInfo];
}
struct ZipExtraField
{
short headerId;
short dataSize;
};
struct ZipExtraField extra = { 0 };
char *filename = (char *)malloc(fileInfo.size_filename + 1);
unzGetCurrentFileInfo(zip, &fileInfo, filename, fileInfo.size_filename + 1, NULL, 0, NULL, 0);
unzGetCurrentFileInfo(zip, &fileInfo, filename, fileInfo.size_filename + 1, &extra, sizeof(struct ZipExtraField), NULL, 0);
filename[fileInfo.size_filename] = '\0';
NSLog(@"Filename: %s", filename);
//extra.data = (char *)malloc(fileInfo.size_file_extra);
//unzGetLocalExtrafield(zip, &extra, sizeof(struct ZipExtraField));
NSLog(@"Header ID: %ul", fileInfo.size_file_extra);
//NSLog(@"Data: %s", extra.data);
// Check if it contains directory
NSString *strPath = [NSString stringWithCString:filename encoding:NSUTF8StringEncoding];
@@ -144,6 +161,8 @@
ret = unzGoToNextFile(zip);
continue;
}
NSLog(@"External file attributes: %lu", fileInfo.external_fa);
FILE *fp = fopen((const char*)[fullPath UTF8String], "wb");
while (fp) {
@@ -19,6 +19,8 @@
B215FB6D143AD6FF003AC546 /* TestArchive.zip in Resources */ = {isa = PBXBuildFile; fileRef = B215FB6C143AD6FF003AC546 /* TestArchive.zip */; };
B23FCC7F1558F1B70026375C /* TestPasswordArchive.zip in Resources */ = {isa = PBXBuildFile; fileRef = B23FCC7E1558F1B70026375C /* TestPasswordArchive.zip */; };
C5AE4E64155A12760045F3ED /* IncorrectHeaders.zip in Resources */ = {isa = PBXBuildFile; fileRef = C5AE4E63155A12760045F3ED /* IncorrectHeaders.zip */; };
C5AE4E6D155A8B010045F3ED /* SymbolicLink.zip in Resources */ = {isa = PBXBuildFile; fileRef = C5AE4E6C155A8B010045F3ED /* SymbolicLink.zip */; };
C5AE4E70155A96CF0045F3ED /* ZipTest.zip in Resources */ = {isa = PBXBuildFile; fileRef = C5AE4E6F155A96CF0045F3ED /* ZipTest.zip */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -42,6 +44,8 @@
B215FB6C143AD6FF003AC546 /* TestArchive.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = TestArchive.zip; sourceTree = "<group>"; };
B23FCC7E1558F1B70026375C /* TestPasswordArchive.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = TestPasswordArchive.zip; sourceTree = "<group>"; };
C5AE4E63155A12760045F3ED /* IncorrectHeaders.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = IncorrectHeaders.zip; sourceTree = "<group>"; };
C5AE4E6C155A8B010045F3ED /* SymbolicLink.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = SymbolicLink.zip; sourceTree = "<group>"; };
C5AE4E6F155A96CF0045F3ED /* ZipTest.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = ZipTest.zip; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -116,11 +120,13 @@
B215FB5E143AD505003AC546 /* SSZipArchiveTests */ = {
isa = PBXGroup;
children = (
C5AE4E6F155A96CF0045F3ED /* ZipTest.zip */,
B215FB61143AD514003AC546 /* SSZipArchiveTests.m */,
B215FB5F143AD514003AC546 /* SSZipArchiveTests-Info.plist */,
C5AE4E63155A12760045F3ED /* IncorrectHeaders.zip */,
B215FB6C143AD6FF003AC546 /* TestArchive.zip */,
B23FCC7E1558F1B70026375C /* TestPasswordArchive.zip */,
C5AE4E6C155A8B010045F3ED /* SymbolicLink.zip */,
);
name = SSZipArchiveTests;
sourceTree = "<group>";
@@ -180,6 +186,8 @@
B215FB6D143AD6FF003AC546 /* TestArchive.zip in Resources */,
B23FCC7F1558F1B70026375C /* TestPasswordArchive.zip in Resources */,
C5AE4E64155A12760045F3ED /* IncorrectHeaders.zip in Resources */,
C5AE4E6D155A8B010045F3ED /* SymbolicLink.zip in Resources */,
C5AE4E70155A96CF0045F3ED /* ZipTest.zip in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
+16 -4
View File
@@ -84,6 +84,18 @@
STAssertTrue([actualReadmeTxtMD5 isEqualToString:intendedReadmeTxtMD5], @"Readme.txt MD5 digest should match original.");
}
- (void)testUnzippingWithSymlinkedFileInside {
NSString* zipPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"ZipTest" ofType:@"zip"];
NSString* outputPath = [self _cachesPath:@"SymbolicLink"];
[SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:self];
BOOL symbolicLinkPersists = NO;
STAssertTrue(symbolicLinkPersists, @"Symbolic links should persist from the original archive to the outputted files.");
}
// Commented out to avoid checking in several gig file into the repository. Simply add a file named
// `LargeArchive.zip` to the project and uncomment out these lines to test.
@@ -99,22 +111,22 @@
#pragma mark - SSZipArchiveDelegate
- (void)zipArchiveWillUnzipArchiveAtPath:(NSString *)path zipInfo:(unz_global_info)zipInfo {
NSLog(@"*** zipArchiveWillUnzipArchiveAtPath: `%@` zipInfo:", path);
//NSLog(@"*** zipArchiveWillUnzipArchiveAtPath: `%@` zipInfo:", path);
}
- (void)zipArchiveDidUnzipArchiveAtPath:(NSString *)path zipInfo:(unz_global_info)zipInfo unzippedPath:(NSString *)unzippedPath {
NSLog(@"*** zipArchiveDidUnzipArchiveAtPath: `%@` zipInfo: unzippedPath: `%@`", path, unzippedPath);
//NSLog(@"*** zipArchiveDidUnzipArchiveAtPath: `%@` zipInfo: unzippedPath: `%@`", path, unzippedPath);
}
- (void)zipArchiveWillUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath fileInfo:(unz_file_info)fileInfo {
NSLog(@"*** zipArchiveWillUnzipFileAtIndex: `%ld` totalFiles: `%ld` archivePath: `%@` fileInfo:", fileIndex, totalFiles, archivePath);
//NSLog(@"*** zipArchiveWillUnzipFileAtIndex: `%ld` totalFiles: `%ld` archivePath: `%@` fileInfo:", fileIndex, totalFiles, archivePath);
}
- (void)zipArchiveDidUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath fileInfo:(unz_file_info)fileInfo {
NSLog(@"*** zipArchiveDidUnzipFileAtIndex: `%ld` totalFiles: `%ld` archivePath: `%@` fileInfo:", fileIndex, totalFiles, archivePath);
//NSLog(@"*** zipArchiveDidUnzipFileAtIndex: `%ld` totalFiles: `%ld` archivePath: `%@` fileInfo:", fileIndex, totalFiles, archivePath);
}
Binary file not shown.
BIN
View File
Binary file not shown.