Skip to content
This repository
Browse code

Merge pull request #31 from danielmatzke/master

fix that file modification date is stored in wrong format
  • Loading branch information...
commit 3812812b2ba527a384ec6abc24cca701202b0952 2 parents 1442274 + 3588d02
Matt Connolly authored

Showing 1 changed file with 34 additions and 15 deletions. Show diff stats Hide diff stats

  1. +34 15 ZipArchive.m
49 ZipArchive.m
@@ -110,22 +110,32 @@ -(BOOL) addFileToZip:(NSString*) file newname:(NSString*) newname;
110 110 if( !_zipFile )
111 111 return NO;
112 112 // tm_zip filetime;
113   - time_t current;
114   - time( &current );
115 113
116 114 zip_fileinfo zipInfo = {{0}};
117   - zipInfo.dosDate = (unsigned long) current;
118   -
  115 +
  116 + NSDate* fileDate = nil;
  117 +
119 118 NSError* error = nil;
120 119 NSDictionary* attr = [_fileManager _attributesOfItemAtPath:file followingSymLinks:YES error:&error];
121 120 if( attr )
122   - {
123   - NSDate* fileDate = (NSDate*)[attr objectForKey:NSFileModificationDate];
124   - if( fileDate )
125   - {
126   - zipInfo.dosDate = [fileDate timeIntervalSinceDate:[self Date1980] ];
127   - }
128   - }
  121 + fileDate = (NSDate*)[attr objectForKey:NSFileModificationDate];
  122 +
  123 + if( fileDate == nil )
  124 + fileDate = [NSDate date];
  125 +
  126 +
  127 + NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
  128 + NSDateComponents* components = [gregorianCalendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay |
  129 + NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond fromDate:fileDate];
  130 + [gregorianCalendar release];
  131 +
  132 + zipInfo.tmz_date.tm_sec = (uInt)components.second;
  133 + zipInfo.tmz_date.tm_min = (uInt)components.minute;
  134 + zipInfo.tmz_date.tm_hour = (uInt)components.hour;
  135 + zipInfo.tmz_date.tm_mday = (uInt)components.day;
  136 + zipInfo.tmz_date.tm_mon = (uInt)components.month;
  137 + zipInfo.tmz_date.tm_year = (uInt)components.year;
  138 +
129 139
130 140 int ret ;
131 141 NSData* data = nil;
@@ -349,11 +359,20 @@ -(BOOL) UnzipFileTo:(NSString*) path overWrite:(BOOL) overwrite
349 359 [(NSMutableArray*)_unzippedFiles addObject:fullPath];
350 360
351 361 // set the orignal datetime property
352   - if( fileInfo.dosDate!=0 )
  362 + if( fileInfo.tmu_date.tm_year!=0 )
353 363 {
354   - NSDate* orgDate = [[NSDate alloc]
355   - initWithTimeInterval:(NSTimeInterval)fileInfo.dosDate
356   - sinceDate:[self Date1980] ];
  364 + NSDateComponents* components = [[NSDateComponents alloc] init];
  365 + components.second = fileInfo.tmu_date.tm_sec;
  366 + components.minute = fileInfo.tmu_date.tm_min;
  367 + components.hour = fileInfo.tmu_date.tm_hour;
  368 + components.day = fileInfo.tmu_date.tm_mday;
  369 + components.month = fileInfo.tmu_date.tm_mon;
  370 + components.year = fileInfo.tmu_date.tm_year;
  371 +
  372 + NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
  373 + NSDate* orgDate = [[gregorianCalendar dateFromComponents:components] retain];
  374 + [components release];
  375 + [gregorianCalendar release];
357 376
358 377 NSDictionary* attr = [NSDictionary dictionaryWithObject:orgDate forKey:NSFileModificationDate]; //[_fileManager fileAttributesAtPath:fullPath traverseLink:YES];
359 378 if( attr )

0 comments on commit 3812812

Please sign in to comment.
Something went wrong with that request. Please try again.