Skip to content

Commit d6d6e06

Browse files
committed
More fixes for Linux.
1 parent df0b0d8 commit d6d6e06

File tree

10 files changed

+54
-47
lines changed

10 files changed

+54
-47
lines changed

XADArchive.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ -(NSData *)contentsOfEntry:(NSInteger)n
868868
return nil;
869869
}
870870

871-
-(nullable NSData *)contentsOfEntry:(NSInteger)n error:(NSError**)error
871+
-(NSData *)contentsOfEntry:(NSInteger)n error:(NSError**)error
872872
{
873873
NSDictionary *dict=[self dataForkParserDictionaryForEntry:n];
874874
if(!dict) return [NSData data]; // Special case for files with only a resource fork
@@ -1464,7 +1464,7 @@ -(CSHandle *)resourceHandleForEntry:(NSInteger)n nserror:(NSError **)error
14641464
}
14651465
return nil;
14661466
}
1467-
NSNumber *isdir=resdict[XADIsDirectoryKey];
1467+
NSNumber *isdir=[resdict objectForKey:XADIsDirectoryKey];
14681468
if(isdir&&isdir.boolValue) {
14691469
if (error) {
14701470
*error = [NSError errorWithDomain:XADErrorDomain code:XADErrorFileDirectory userInfo:nil];

XADArchiveParser.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ +(XADArchiveParser *)archiveParserForFileURL:(NSURL *)filename
560560
{
561561
// An empty array means scanning failed. Set a flag to
562562
// warn the caller, and fall through to single-file mode.
563-
props[XADVolumeScanningFailedKey] = @YES;
563+
[props setValue:[NSNumber numberWithBool:YES] forKey:XADVolumeScanningFailedKey];
564564
}
565565
}
566566
}
@@ -571,7 +571,7 @@ +(XADArchiveParser *)archiveParserForFileURL:(NSURL *)filename
571571
parser.resourceFork = fork;
572572
parser.filename = filename.path;
573573

574-
props[XADVolumesKey] = @[filename.path];
574+
[props setValue:[NSArray arrayWithObject:filename.path] forKey:XADVolumesKey];
575575
[parser addPropertiesFromDictionary:props];
576576

577577
return [parser autorelease];
@@ -1067,7 +1067,7 @@ + (void)throwExceptionFromError:(NSError *)error
10671067
return;
10681068
}
10691069
NSMutableDictionary *exceptionUserInfo = [error.userInfo mutableCopy];
1070-
exceptionUserInfo[@"XADError"] = @((XADError)error.code);
1070+
[exceptionUserInfo setValue:[NSNumber numberWithInt:(XADError)error.code] forKey:@"XADError"];
10711071
[[[NSException alloc] initWithName:XADExceptionName reason:[XADException describeXADError:(XADError)error.code]
10721072
userInfo:exceptionUserInfo] raise];
10731073

@@ -1550,7 +1550,7 @@ +(XADArchiveParser *)archiveParserForFileURL:(NSURL *)filename error:(NSError **
15501550
return nil;
15511551
}
15521552
if (errorptr) {
1553-
*errorptr = [NSError errorWithDomain:XADErrorDomain code:XADErrorNotSupported userInfo:@{NSURLErrorKey: filename}];
1553+
*errorptr = [NSError errorWithDomain:XADErrorDomain code:XADErrorNotSupported userInfo:[NSDictionary dictionaryWithObjectsAndKeys:filename, NSURLErrorKey, nil]];
15541554
}
15551555
return nil;
15561556
}
@@ -1569,7 +1569,7 @@ +(XADArchiveParser *)archiveParserForPath:(NSString *)filename nserror:(NSError
15691569
return nil;
15701570
}
15711571
if (errorptr) {
1572-
*errorptr = [NSError errorWithDomain:XADErrorDomain code:XADErrorNotSupported userInfo:@{NSFilePathErrorKey: filename}];
1572+
*errorptr = [NSError errorWithDomain:XADErrorDomain code:XADErrorNotSupported userInfo:[NSDictionary dictionaryWithObjectsAndKeys:filename, NSFilePathErrorKey, nil]];
15731573
}
15741574
return nil;
15751575
}

XADException.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,22 @@ +(XADError)parseException:(id)exception
7979
return XADErrorUnknown;
8080
}
8181

82-
+(NSError*)parseExceptionReturningNSError:(nonnull id)exception
82+
+(NSError*)parseExceptionReturningNSError:(id)exception
8383
{
8484
if([exception isKindOfClass:[NSException class]])
8585
{
8686
NSException *e=exception;
8787
NSString *name=[e name];
88-
NSMutableDictionary *usrInfo = [NSMutableDictionary dictionaryWithDictionary:e.userInfo ?: @{}];
89-
usrInfo[XADExceptionReasonKey] = e.reason;
88+
NSMutableDictionary *usrInfo = [NSMutableDictionary dictionaryWithDictionary:e.userInfo ?: [NSDictionary dictionary]];
89+
[usrInfo setValue:e.reason forKey:XADExceptionReasonKey];
9090
if ([name isEqualToString:XADExceptionName]) {
91-
XADError errVal = [[e userInfo][@"XADError"] intValue];
91+
XADError errVal = [[[e userInfo] objectForKey:@"XADError"] intValue];
9292
return [NSError errorWithDomain:XADErrorDomain code:errVal userInfo:usrInfo];
9393
} else if([name isEqualToString:CSCannotOpenFileException]) {
9494
return [NSError errorWithDomain:XADErrorDomain code:XADErrorOpenFile userInfo:usrInfo];
9595
} else if([name isEqualToString:CSFileErrorException]) {
9696
if (usrInfo && [usrInfo objectForKey:@"ErrNo"]) {
97-
int errNo = [usrInfo[@"ErrNo"] intValue];
97+
int errNo = [[usrInfo objectForKey:@"ErrNo"] intValue];
9898
[usrInfo removeObjectForKey:@"ErrNo"];
9999
return [NSError errorWithDomain:NSPOSIXErrorDomain code:errNo userInfo:usrInfo];
100100
}

XADPlatformLinux.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ +(XADError)updateFileAttributesAtPath:(NSString *)path
105105
if(chmod(cpath,mode&~S_IFMT)!=0) return XADUnknownError; // TODO: bette error
106106
}
107107

108-
return XADNoError;
108+
return XADErrorNone;
109109
}
110110

111111
+(XADError)createLinkAtPath:(NSString *)path withDestinationPath:(NSString *)link
@@ -115,7 +115,7 @@ +(XADError)createLinkAtPath:(NSString *)path withDestinationPath:(NSString *)lin
115115
if(lstat(destcstr,&st)==0) unlink(destcstr);
116116
if(symlink([link fileSystemRepresentation],destcstr)!=0) return XADLinkError;
117117

118-
return XADNoError;
118+
return XADErrorNone;
119119
}
120120

121121

XADPlatformWindows.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ +(XADError)updateFileAttributesAtPath:(NSString *)path
9797
SetFileAttributesW(wpath,newattributes);
9898
}
9999

100-
return XADNoError;
100+
return XADErrorNone;
101101
}
102102

103103
+(XADError)createLinkAtPath:(NSString *)path withDestinationPath:(NSString *)link

XADPlatformiOS.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ +(XADError)updateFileAttributesAtPath:(NSString *)path
121121
// Finally, set all attributes.
122122
setattrlist(cpath,&list,attrdata,attrptr-attrdata,FSOPT_NOFOLLOW);
123123

124-
return XADNoError;
124+
return XADErrorNone;
125125
}
126126

127127
+(XADError)createLinkAtPath:(NSString *)path withDestinationPath:(NSString *)link
@@ -131,7 +131,7 @@ +(XADError)createLinkAtPath:(NSString *)path withDestinationPath:(NSString *)lin
131131
if(lstat(destcstr,&st)==0) unlink(destcstr);
132132
if(symlink([link fileSystemRepresentation],destcstr)!=0) return XADLinkError;
133133

134-
return XADNoError;
134+
return XADErrorNone;
135135
}
136136

137137

XADSimpleUnarchiver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ XADEXPORT
131131

132132
-(XADError)parse;
133133
-(XADError)_setupSubArchiveForEntryWithDataFork:(NSDictionary *)datadict resourceFork:(NSDictionary *)resourcedict;
134+
-(BOOL)_setupSubArchiveForEntryWithDataFork:(NSDictionary *)datadict resourceFork:(NSDictionary *)resourcedict error:(NSError**)outError;
134135

135136
-(XADError)unarchive;
136137
-(XADError)_unarchiveRegularArchive;

XADSimpleUnarchiver.m

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ -(BOOL)parseWithError:(NSError**)error
328328
{
329329
if(entries.count) {
330330
if (error) {
331-
*error = [NSError errorWithDomain:XADErrorDomain code:XADErrorBadParameters userInfo:@{NSLocalizedDescriptionKey: @"You can not call parseAndUnarchive twice", NSDebugDescriptionErrorKey: @"You can not call parseAndUnarchive twice"}];
331+
*error = [NSError errorWithDomain:XADErrorDomain code:XADErrorBadParameters userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"You can not call parseAndUnarchive twice", NSLocalizedDescriptionKey, nil]];
332332
}
333333

334334
return NO;
@@ -344,26 +344,26 @@ -(BOOL)parseWithError:(NSError**)error
344344
if (extractsubarchives) {
345345
// Check if we have a single entry, which is an archive.
346346
if (entries.count==1) {
347-
NSDictionary *entry=entries[0];
348-
NSNumber *archnum=entry[XADIsArchiveKey];
347+
NSDictionary *entry=[entries objectAtIndex:0];
348+
NSNumber *archnum=[entry objectForKey:XADIsArchiveKey];
349349
BOOL isarc=archnum&&archnum.boolValue;
350350
if(isarc) return [self _setupSubArchiveForEntryWithDataFork:entry resourceFork:nil error:error];
351351
}
352352

353353
// Check if we have two entries, which are data and resource forks
354354
// of the same archive.
355355
if (entries.count==2) {
356-
NSDictionary *first=entries[0];
357-
NSDictionary *second=entries[1];
358-
XADPath *name1=first[XADFileNameKey];
359-
XADPath *name2=second[XADFileNameKey];
360-
NSNumber *archnum1=first[XADIsArchiveKey];
361-
NSNumber *archnum2=second[XADIsArchiveKey];
356+
NSDictionary *first=[entries objectAtIndex:0];
357+
NSDictionary *second=[entries objectAtIndex:1];
358+
XADPath *name1=[first objectForKey:XADFileNameKey];
359+
XADPath *name2=[second objectForKey:XADFileNameKey];
360+
NSNumber *archnum1=[first objectForKey:XADIsArchiveKey];
361+
NSNumber *archnum2=[second objectForKey:XADIsArchiveKey];
362362
BOOL isarc1=archnum1&&archnum1.boolValue;
363363
BOOL isarc2=archnum2&&archnum2.boolValue;
364364

365365
if ([name1 isEqual:name2] && (isarc1||isarc2)) {
366-
NSNumber *resnum=first[XADIsResourceForkKey];
366+
NSNumber *resnum=[first objectForKey:XADIsResourceForkKey];
367367
NSDictionary *datafork,*resourcefork;
368368
if (resnum&&resnum.boolValue) {
369369
datafork=second;
@@ -374,7 +374,7 @@ -(BOOL)parseWithError:(NSError**)error
374374
}
375375

376376
// TODO: Handle resource forks for archives that require them.
377-
NSNumber *archnum=datafork[XADIsArchiveKey];
377+
NSNumber *archnum=[datafork objectForKey:XADIsArchiveKey];
378378
if(archnum&&archnum.boolValue) {
379379
return [self _setupSubArchiveForEntryWithDataFork:datafork resourceFork:resourcefork error:error];
380380
}

XADUnarchiver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ nserror:(NSError **)errorptr;
110110
-(XADError)_updateFileAttributesAtPath:(NSString *)path forEntryWithDictionary:(NSDictionary *)dict
111111
deferDirectories:(BOOL)defer;
112112
-(XADError)_ensureDirectoryExists:(NSString *)path;
113+
-(BOOL)_ensureDirectoryExists:(NSString *)path error:(NSError**)outError;
113114

114115
-(XADError)runExtractorWithDictionary:(NSDictionary *)dict outputHandle:(CSHandle *)handle;
115116
-(XADError)runExtractorWithDictionary:(NSDictionary *)dict

XADUnarchiver.m

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -324,16 +324,16 @@ -(XADError)extractEntryWithDictionary:(NSDictionary *)dict as:(NSString *)path f
324324
}
325325

326326
// FIXME: Improve extractEntryWithDictionary:as:forceDirectories:error: with an NSError value.
327-
-(BOOL)extractEntryWithDictionary:(NSDictionary *)dict as:(nullable NSString *)path forceDirectories:(BOOL)force error:(NSError**)outErr
327+
-(BOOL)extractEntryWithDictionary:(NSDictionary *)dict as:(NSString *)path forceDirectories:(BOOL)force error:(NSError**)outErr
328328
{
329-
__strong NSError *tmpErr = nil;
329+
NSError *tmpErr = nil;
330330
BOOL okay;
331-
@autoreleasepool {
331+
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
332332

333-
NSNumber *dirnum=dict[XADIsDirectoryKey];
334-
NSNumber *linknum=dict[XADIsLinkKey];
335-
NSNumber *resnum=dict[XADIsResourceForkKey];
336-
NSNumber *archivenum=dict[XADIsArchiveKey];
333+
NSNumber *dirnum=[dict objectForKey:XADIsDirectoryKey];
334+
NSNumber *linknum=[dict objectForKey:XADIsLinkKey];
335+
NSNumber *resnum=[dict objectForKey:XADIsResourceForkKey];
336+
NSNumber *archivenum=[dict objectForKey:XADIsArchiveKey];
337337
BOOL isdir=dirnum&&dirnum.boolValue;
338338
BOOL islink=linknum&&linknum.boolValue;
339339
BOOL isres=resnum&&resnum.boolValue;
@@ -342,7 +342,7 @@ -(BOOL)extractEntryWithDictionary:(NSDictionary *)dict as:(nullable NSString *)p
342342
// If we were not given a path, pick one ourselves.
343343
if(!path)
344344
{
345-
XADPath *name=dict[XADFileNameKey];
345+
XADPath *name=[dict objectForKey:XADFileNameKey];
346346
NSString *namestring=name.sanitizedPathString;
347347

348348
if(destination) path=[destination stringByAppendingPathComponent:namestring];
@@ -367,6 +367,7 @@ -(BOOL)extractEntryWithDictionary:(NSDictionary *)dict as:(nullable NSString *)p
367367
XADError error=0;
368368

369369
okay=[self _ensureDirectoryExists:path.stringByDeletingLastPathComponent error:&tmpErr];
370+
[tmpErr retain];
370371
if(!okay) goto end;
371372

372373
// Attempt to extract embedded archives if requested.
@@ -377,6 +378,7 @@ -(BOOL)extractEntryWithDictionary:(NSDictionary *)dict as:(nullable NSString *)p
377378
if([delegate unarchiver:self shouldExtractArchiveEntryWithDictionary:dict to:unarchiverpath])
378379
{
379380
okay=[self _extractArchiveEntryWithDictionary:dict to:unarchiverpath name:path.lastPathComponent error:&tmpErr];
381+
[tmpErr retain];
380382
// If extraction was attempted, and succeeded for failed, skip everything else.
381383
// Otherwise, if the archive couldn't be opened, fall through and extract normally.
382384
if(!okay && ([tmpErr.domain isEqualToString:XADErrorDomain] && tmpErr.code != XADErrorSubArchive)) goto end;
@@ -399,7 +401,7 @@ -(BOOL)extractEntryWithDictionary:(NSDictionary *)dict as:(nullable NSString *)p
399401
tmpErr = nil;
400402
} else {
401403
okay = NO;
402-
tmpErr = [NSError errorWithDomain:XADErrorDomain code:error userInfo:nil];
404+
tmpErr = [[NSError alloc] initWithDomain:XADErrorDomain code:error userInfo:nil];
403405
}
404406
}
405407
break;
@@ -413,7 +415,7 @@ -(BOOL)extractEntryWithDictionary:(NSDictionary *)dict as:(nullable NSString *)p
413415
tmpErr = nil;
414416
} else {
415417
okay = NO;
416-
tmpErr = [NSError errorWithDomain:XADErrorDomain code:error userInfo:nil];
418+
tmpErr = [[NSError alloc] initWithDomain:XADErrorDomain code:error userInfo:nil];
417419
}
418420
}
419421
break;
@@ -443,15 +445,15 @@ -(BOOL)extractEntryWithDictionary:(NSDictionary *)dict as:(nullable NSString *)p
443445
tmpErr = nil;
444446
} else {
445447
okay = NO;
446-
tmpErr = [NSError errorWithDomain:XADErrorDomain code:error userInfo:nil];
448+
tmpErr = [[NSError alloc] initWithDomain:XADErrorDomain code:error userInfo:nil];
447449
}
448450
break;
449451

450452
default:
451453
// TODO: better error
452454
error=XADErrorBadParameters;
453455
okay = NO;
454-
tmpErr = [NSError errorWithDomain:XADErrorDomain code:XADErrorBadParameters userInfo:nil];
456+
tmpErr = [[NSError alloc] initWithDomain:XADErrorDomain code:XADErrorBadParameters userInfo:nil];
455457

456458
break;
457459
}
@@ -479,18 +481,21 @@ -(BOOL)extractEntryWithDictionary:(NSDictionary *)dict as:(nullable NSString *)p
479481
tmpErr = nil;
480482
} else {
481483
okay = NO;
482-
tmpErr = [NSError errorWithDomain:XADErrorDomain code:error userInfo:nil];
484+
tmpErr = [[NSError alloc] initWithDomain:XADErrorDomain code:error userInfo:nil];
483485
}
484486

485487
// Report success or failure
486488
end:
487-
if(delegate && [delegate respondsToSelector:@selector(unarchiver:didExtractEntryWithDictionary:to:error:)])
489+
if([delegate respondsToSelector:@selector(unarchiver:didExtractEntryWithDictionary:to:error:)])
488490
{
489491
[delegate unarchiver:self didExtractEntryWithDictionary:dict to:path nserror:okay ? nil : tmpErr];
490492
}
491-
}
493+
[pool release];
494+
492495
if (outErr && tmpErr) {
493-
*outErr = tmpErr;
496+
*outErr = [tmpErr autorelease];
497+
} else if (tmpErr) {
498+
[tmpErr release];
494499
}
495500

496501
return okay;
@@ -877,7 +882,7 @@ -(XADError)_ensureDirectoryExists:(NSString *)path
877882
if ([delegate respondsToSelector:@selector(unarchiver:didCreateDirectory:)]) {
878883
[delegate unarchiver:self didCreateDirectory:path];
879884
}
880-
return XADNoError;
885+
return XADErrorNone;
881886
}
882887
#endif
883888
else return XADErrorMakeDirectory;
@@ -1029,7 +1034,7 @@ -(BOOL)runExtractorWithDictionary:(NSDictionary *)dict
10291034
}
10301035

10311036
// Try to find the size of this entry.
1032-
NSNumber *sizenum=dict[XADFileSizeKey];
1037+
NSNumber *sizenum=[dict objectForKey:XADFileSizeKey];
10331038
off_t size=0;
10341039
if(sizenum != nil)
10351040
{
@@ -1105,7 +1110,7 @@ -(BOOL)runExtractorWithDictionary:(NSDictionary *)dict
11051110

11061111
// Check if the file has already been marked as corrupt, and
11071112
// give up without testing checksum if so.
1108-
NSNumber *iscorrupt=dict[XADIsCorruptedKey];
1113+
NSNumber *iscorrupt=[dict objectForKey:XADIsCorruptedKey];
11091114
if(iscorrupt&&iscorrupt.boolValue) {
11101115
if (outError) {
11111116
*outError = [NSError errorWithDomain:XADErrorDomain code:XADErrorDecrunch userInfo:nil];

0 commit comments

Comments
 (0)