-
Notifications
You must be signed in to change notification settings - Fork 21
Support archival and restoration of POSIX permissions #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c2f4fa7
e7ed5a4
42a009c
7a47fd7
983a706
6c50353
34f4dbc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -626,7 +626,10 @@ - (BOOL)extractFilesTo:(NSString *)destinationDirectory | |
| UZKLogDebug("Closing file handle"); | ||
| [deflatedFileHandle closeFile]; | ||
|
|
||
| NSDictionary* attribs = [NSDictionary dictionaryWithObjectsAndKeys:info.timestamp, NSFileModificationDate, nil]; | ||
| // Retain the permission attribute of a file | ||
abbeycode marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| NSDictionary* attribs = @{NSFileModificationDate: info.timestamp, | ||
| NSFilePosixPermissions: info.posixPermissions}; | ||
|
|
||
| [[NSFileManager defaultManager] setAttributes:attribs ofItemAtPath:path error:nil]; | ||
|
|
||
| if (!extractSuccess) { | ||
|
|
@@ -1058,6 +1061,7 @@ - (BOOL)writeData:(NSData *)data | |
| return [self writeData:data | ||
| filePath:filePath | ||
| fileDate:nil | ||
| posixPermissions:0 | ||
| compressionMethod:UZKCompressionMethodDefault | ||
| password:nil | ||
| overwrite:YES | ||
|
|
@@ -1072,6 +1076,7 @@ - (BOOL)writeData:(NSData *)data | |
| return [self writeData:data | ||
| filePath:filePath | ||
| fileDate:nil | ||
| posixPermissions:0 | ||
| compressionMethod:UZKCompressionMethodDefault | ||
| password:nil | ||
| overwrite:YES | ||
|
|
@@ -1087,6 +1092,7 @@ - (BOOL)writeData:(NSData *)data | |
| return [self writeData:data | ||
| filePath:filePath | ||
| fileDate:fileDate | ||
| posixPermissions:0 | ||
| compressionMethod:UZKCompressionMethodDefault | ||
| password:nil | ||
| overwrite:YES | ||
|
|
@@ -1119,6 +1125,7 @@ - (BOOL)writeData:(NSData *)data | |
| return [self writeData:data | ||
| filePath:filePath | ||
| fileDate:fileDate | ||
| posixPermissions:0 | ||
| compressionMethod:method | ||
| password:password | ||
| overwrite:YES | ||
|
|
@@ -1145,18 +1152,20 @@ - (BOOL)writeData:(NSData *)data | |
|
|
||
| - (BOOL)writeData:(NSData *)data | ||
| filePath:(NSString *)filePath | ||
| fileDate:(NSDate *)fileDate | ||
| fileDate:(nullable NSDate *)fileDate | ||
| posixPermissions:(unsigned long)posixPermissions | ||
| compressionMethod:(UZKCompressionMethod)method | ||
| password:(NSString *)password | ||
| password:(nullable NSString *)password | ||
| overwrite:(BOOL)overwrite | ||
| error:(NSError * __autoreleasing*)error | ||
| error:(NSError *__autoreleasing*)error | ||
| { | ||
| #pragma clang diagnostic push | ||
| #pragma clang diagnostic ignored "-Wdeprecated-declarations" | ||
| return [self writeData:data | ||
| filePath:filePath | ||
| fileDate:fileDate | ||
| compressionMethod:method | ||
| posixPermissions:posixPermissions | ||
| compressionMethod:UZKCompressionMethodDefault | ||
| password:password | ||
| overwrite:overwrite | ||
| progress:nil | ||
|
|
@@ -1172,6 +1181,27 @@ - (BOOL)writeData:(NSData *)data | |
| overwrite:(BOOL)overwrite | ||
| progress:(void (^)(CGFloat percentCompressed))progressBlock | ||
| error:(NSError * __autoreleasing*)error | ||
| { | ||
| return [self writeData:data | ||
| filePath:filePath | ||
| fileDate:fileDate | ||
| posixPermissions:0 | ||
| compressionMethod:method | ||
| password:password | ||
| overwrite:overwrite | ||
| error:error]; | ||
| } | ||
|
|
||
|
|
||
| - (BOOL)writeData:(NSData *)data | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is also an extra overload. |
||
| filePath:(NSString *)filePath | ||
| fileDate:(NSDate *)fileDate | ||
| posixPermissions:(unsigned long)posixPermissions | ||
| compressionMethod:(UZKCompressionMethod)method | ||
| password:(NSString *)password | ||
| overwrite:(BOOL)overwrite | ||
| progress:(void (^)(CGFloat percentCompressed))progressBlock | ||
| error:(NSError * __autoreleasing*)error | ||
| { | ||
| UZKCreateActivity("Writing Data"); | ||
|
|
||
|
|
@@ -1228,6 +1258,7 @@ - (BOOL)writeData:(NSData *)data | |
| } | ||
| filePath:filePath | ||
| fileDate:fileDate | ||
| posixPermissions:posixPermissions | ||
| compressionMethod:method | ||
| password:password | ||
| overwrite:overwrite | ||
|
|
@@ -1243,6 +1274,7 @@ - (BOOL)writeIntoBuffer:(NSString *)filePath | |
| { | ||
| return [self writeIntoBuffer:filePath | ||
| fileDate:nil | ||
| posixPermissions:0 | ||
| compressionMethod:UZKCompressionMethodDefault | ||
| overwrite:YES | ||
| CRC:0 | ||
|
|
@@ -1258,6 +1290,7 @@ - (BOOL)writeIntoBuffer:(NSString *)filePath | |
| { | ||
| return [self writeIntoBuffer:filePath | ||
| fileDate:fileDate | ||
| posixPermissions:0 | ||
| compressionMethod:UZKCompressionMethodDefault | ||
| overwrite:YES | ||
| CRC:0 | ||
|
|
@@ -1274,6 +1307,7 @@ - (BOOL)writeIntoBuffer:(NSString *)filePath | |
| { | ||
| return [self writeIntoBuffer:filePath | ||
| fileDate:fileDate | ||
| posixPermissions:0 | ||
| compressionMethod:method | ||
| overwrite:YES | ||
| CRC:0 | ||
|
|
@@ -1291,6 +1325,7 @@ - (BOOL)writeIntoBuffer:(NSString *)filePath | |
| { | ||
| return [self writeIntoBuffer:filePath | ||
| fileDate:fileDate | ||
| posixPermissions:0 | ||
| compressionMethod:method | ||
| overwrite:overwrite | ||
| CRC:0 | ||
|
|
@@ -1309,6 +1344,7 @@ - (BOOL)writeIntoBuffer:(NSString *)filePath | |
| { | ||
| return [self writeIntoBuffer:filePath | ||
| fileDate:fileDate | ||
| posixPermissions:0 | ||
| compressionMethod:method | ||
| overwrite:overwrite | ||
| CRC:preCRC | ||
|
|
@@ -1319,6 +1355,7 @@ - (BOOL)writeIntoBuffer:(NSString *)filePath | |
|
|
||
| - (BOOL)writeIntoBuffer:(NSString *)filePath | ||
| fileDate:(NSDate *)fileDate | ||
| posixPermissions:(unsigned long)posixPermissions | ||
| compressionMethod:(UZKCompressionMethod)method | ||
| overwrite:(BOOL)overwrite | ||
| CRC:(uLong)preCRC | ||
|
|
@@ -1380,6 +1417,7 @@ - (BOOL)writeIntoBuffer:(NSString *)filePath | |
| } | ||
| filePath:filePath | ||
| fileDate:fileDate | ||
| posixPermissions:posixPermissions | ||
| compressionMethod:method | ||
| password:password | ||
| overwrite:overwrite | ||
|
|
@@ -1922,6 +1960,7 @@ - (BOOL)performActionWithArchiveOpen:(void(^)(NSError * __autoreleasing*innerErr | |
| - (BOOL)performWriteAction:(int(^)(uLong *crc, NSError * __autoreleasing*innerError))write | ||
| filePath:(NSString *)filePath | ||
| fileDate:(NSDate *)fileDate | ||
| posixPermissions:(unsigned long)posixPermissions | ||
| compressionMethod:(UZKCompressionMethod)method | ||
| password:(NSString *)password | ||
| overwrite:(BOOL)overwrite | ||
|
|
@@ -1973,6 +2012,12 @@ - (BOOL)performWriteAction:(int(^)(uLong *crc, NSError * __autoreleasing*innerEr | |
| UZKLogDebug("Making zip_fileinfo struct for date %{time_t}ld", lrint(fileDate.timeIntervalSince1970)); | ||
| zip_fileinfo zi = [UZKArchive zipFileInfoForDate:fileDate]; | ||
|
|
||
| if (posixPermissions > 0) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This whole if block should be refactored into |
||
|
|
||
abbeycode marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Revert the value of NSFilePosixPermissions to zip external_fa raw data | ||
| zi.external_fa = (posixPermissions + 32768) << 16; | ||
abbeycode marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
abbeycode marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const char *passwordStr = NULL; | ||
|
|
||
| if (password) { | ||
|
|
@@ -2653,6 +2698,7 @@ + (zip_fileinfo)zipFileInfoForDate:(NSDate *)fileDate | |
| zi.tmz_date.tm_year = (uInt)date.year; | ||
| zi.internal_fa = 0; | ||
| zi.external_fa = 0; | ||
| // zi.external_fa = 2175008768; // default posixPermissions value on zip: 2175008768 (0644U) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this commented code. |
||
| zi.dosDate = 0; | ||
|
|
||
| return zi; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,11 +73,24 @@ typedef NS_ENUM(NSInteger, UZKCompressionMethod) { | |
| */ | ||
| @property (readonly) BOOL isDirectory; | ||
|
|
||
| /** | ||
| * YES if the item is a symLink | ||
| */ | ||
| @property (readonly) BOOL isSymLink; | ||
|
|
||
| /** | ||
| * YES if the item is a resource fork | ||
| */ | ||
| @property (readonly) BOOL isResourceFork; | ||
|
|
||
| /** | ||
| * The type of compression | ||
| */ | ||
| @property (readonly) UZKCompressionMethod compressionMethod; | ||
|
|
||
|
|
||
| /** | ||
| @brief posixPermissions (posixPermissions of the file,The value from the file attributes - NSFilePosixPermissions) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| */ | ||
| @property (nonatomic, readonly) NSNumber *posixPermissions; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's move this declaration higher up, below |
||
|
|
||
| @end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,14 +35,18 @@ - (instancetype)initWithFileInfo:(unz_file_info64 *)fileInfo filename:(NSString | |
| _zipTMUDate = fileInfo->tmu_date; | ||
| _CRC = fileInfo->crc; | ||
| _isEncryptedWithPassword = (fileInfo->flag & 1) != 0; | ||
| _isDirectory = [filename hasSuffix:@"/"]; | ||
| // _isDirectory = [filename hasSuffix:@"/"]; | ||
| _isDirectory = [self isDirectoryWith:fileInfo]; | ||
| _isSymLink = [self isSymLinkWith:fileInfo->external_fa]; | ||
|
|
||
| if (_isDirectory) { | ||
| _filename = [_filename substringToIndex:_filename.length - 1]; | ||
| } | ||
|
|
||
| _isResourceFork = [[filename pathComponents].firstObject isEqualToString:@"__MACOSX"]; | ||
| _compressionMethod = [self readCompressionMethod:fileInfo->compression_method | ||
| flag:fileInfo->flag]; | ||
| _posixPermissions = @((fileInfo->external_fa >> 16) ? (fileInfo->external_fa >> 16) : 0755U); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| return self; | ||
| } | ||
|
|
@@ -102,4 +106,20 @@ - (NSDate *)readDate:(tm_unz)date | |
| return [calendar dateFromComponents:components]; | ||
| } | ||
|
|
||
| - (BOOL)isDirectoryWith:(unz_file_info64 *)fileInfo { | ||
| // NSLog(@"ISDIR__ %@", S_ISDIR(fileInfo->external_fa)?@"YES":@"NO"); | ||
| uLong type = fileInfo->external_fa >> 0x1D & 0x1F; | ||
| if (0 == (fileInfo->version >> 8)) { //is DOS-archive | ||
| type = fileInfo->external_fa >> 4; | ||
| return (type == 0x01) && ![self isSymLinkWith:fileInfo->external_fa]; | ||
| } | ||
| return (0x02 == type) && ![self isSymLinkWith:fileInfo->external_fa]; | ||
| } | ||
|
|
||
| - (BOOL)isSymLinkWith:(uLong)externalFileAttributes { | ||
|
|
||
| uLong type = externalFileAttributes >> 0x1D & 0x1F; | ||
| return 0x05 == type; | ||
| } | ||
|
|
||
| @end | ||
Uh oh!
There was an error while loading. Please reload this page.