Skip to content

Commit

Permalink
More fixes for Linux.
Browse files Browse the repository at this point in the history
  • Loading branch information
MaddTheSane committed Feb 7, 2025
1 parent df0b0d8 commit d6d6e06
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 47 deletions.
4 changes: 2 additions & 2 deletions XADArchive.m
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ -(NSData *)contentsOfEntry:(NSInteger)n
return nil;
}

-(nullable NSData *)contentsOfEntry:(NSInteger)n error:(NSError**)error
-(NSData *)contentsOfEntry:(NSInteger)n error:(NSError**)error
{
NSDictionary *dict=[self dataForkParserDictionaryForEntry:n];
if(!dict) return [NSData data]; // Special case for files with only a resource fork
Expand Down Expand Up @@ -1464,7 +1464,7 @@ -(CSHandle *)resourceHandleForEntry:(NSInteger)n nserror:(NSError **)error
}
return nil;
}
NSNumber *isdir=resdict[XADIsDirectoryKey];
NSNumber *isdir=[resdict objectForKey:XADIsDirectoryKey];
if(isdir&&isdir.boolValue) {
if (error) {
*error = [NSError errorWithDomain:XADErrorDomain code:XADErrorFileDirectory userInfo:nil];
Expand Down
10 changes: 5 additions & 5 deletions XADArchiveParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ +(XADArchiveParser *)archiveParserForFileURL:(NSURL *)filename
{
// An empty array means scanning failed. Set a flag to
// warn the caller, and fall through to single-file mode.
props[XADVolumeScanningFailedKey] = @YES;
[props setValue:[NSNumber numberWithBool:YES] forKey:XADVolumeScanningFailedKey];
}
}
}
Expand All @@ -571,7 +571,7 @@ +(XADArchiveParser *)archiveParserForFileURL:(NSURL *)filename
parser.resourceFork = fork;
parser.filename = filename.path;

props[XADVolumesKey] = @[filename.path];
[props setValue:[NSArray arrayWithObject:filename.path] forKey:XADVolumesKey];
[parser addPropertiesFromDictionary:props];

return [parser autorelease];
Expand Down Expand Up @@ -1067,7 +1067,7 @@ + (void)throwExceptionFromError:(NSError *)error
return;
}
NSMutableDictionary *exceptionUserInfo = [error.userInfo mutableCopy];
exceptionUserInfo[@"XADError"] = @((XADError)error.code);
[exceptionUserInfo setValue:[NSNumber numberWithInt:(XADError)error.code] forKey:@"XADError"];
[[[NSException alloc] initWithName:XADExceptionName reason:[XADException describeXADError:(XADError)error.code]
userInfo:exceptionUserInfo] raise];

Expand Down Expand Up @@ -1550,7 +1550,7 @@ +(XADArchiveParser *)archiveParserForFileURL:(NSURL *)filename error:(NSError **
return nil;
}
if (errorptr) {
*errorptr = [NSError errorWithDomain:XADErrorDomain code:XADErrorNotSupported userInfo:@{NSURLErrorKey: filename}];
*errorptr = [NSError errorWithDomain:XADErrorDomain code:XADErrorNotSupported userInfo:[NSDictionary dictionaryWithObjectsAndKeys:filename, NSURLErrorKey, nil]];
}
return nil;
}
Expand All @@ -1569,7 +1569,7 @@ +(XADArchiveParser *)archiveParserForPath:(NSString *)filename nserror:(NSError
return nil;
}
if (errorptr) {
*errorptr = [NSError errorWithDomain:XADErrorDomain code:XADErrorNotSupported userInfo:@{NSFilePathErrorKey: filename}];
*errorptr = [NSError errorWithDomain:XADErrorDomain code:XADErrorNotSupported userInfo:[NSDictionary dictionaryWithObjectsAndKeys:filename, NSFilePathErrorKey, nil]];
}
return nil;
}
Expand Down
10 changes: 5 additions & 5 deletions XADException.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,22 @@ +(XADError)parseException:(id)exception
return XADErrorUnknown;
}

+(NSError*)parseExceptionReturningNSError:(nonnull id)exception
+(NSError*)parseExceptionReturningNSError:(id)exception
{
if([exception isKindOfClass:[NSException class]])
{
NSException *e=exception;
NSString *name=[e name];
NSMutableDictionary *usrInfo = [NSMutableDictionary dictionaryWithDictionary:e.userInfo ?: @{}];
usrInfo[XADExceptionReasonKey] = e.reason;
NSMutableDictionary *usrInfo = [NSMutableDictionary dictionaryWithDictionary:e.userInfo ?: [NSDictionary dictionary]];
[usrInfo setValue:e.reason forKey:XADExceptionReasonKey];
if ([name isEqualToString:XADExceptionName]) {
XADError errVal = [[e userInfo][@"XADError"] intValue];
XADError errVal = [[[e userInfo] objectForKey:@"XADError"] intValue];
return [NSError errorWithDomain:XADErrorDomain code:errVal userInfo:usrInfo];
} else if([name isEqualToString:CSCannotOpenFileException]) {
return [NSError errorWithDomain:XADErrorDomain code:XADErrorOpenFile userInfo:usrInfo];
} else if([name isEqualToString:CSFileErrorException]) {
if (usrInfo && [usrInfo objectForKey:@"ErrNo"]) {
int errNo = [usrInfo[@"ErrNo"] intValue];
int errNo = [[usrInfo objectForKey:@"ErrNo"] intValue];
[usrInfo removeObjectForKey:@"ErrNo"];
return [NSError errorWithDomain:NSPOSIXErrorDomain code:errNo userInfo:usrInfo];
}
Expand Down
4 changes: 2 additions & 2 deletions XADPlatformLinux.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ +(XADError)updateFileAttributesAtPath:(NSString *)path
if(chmod(cpath,mode&~S_IFMT)!=0) return XADUnknownError; // TODO: bette error
}

return XADNoError;
return XADErrorNone;
}

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

return XADNoError;
return XADErrorNone;
}


Expand Down
2 changes: 1 addition & 1 deletion XADPlatformWindows.m
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ +(XADError)updateFileAttributesAtPath:(NSString *)path
SetFileAttributesW(wpath,newattributes);
}

return XADNoError;
return XADErrorNone;
}

+(XADError)createLinkAtPath:(NSString *)path withDestinationPath:(NSString *)link
Expand Down
4 changes: 2 additions & 2 deletions XADPlatformiOS.m
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ +(XADError)updateFileAttributesAtPath:(NSString *)path
// Finally, set all attributes.
setattrlist(cpath,&list,attrdata,attrptr-attrdata,FSOPT_NOFOLLOW);

return XADNoError;
return XADErrorNone;
}

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

return XADNoError;
return XADErrorNone;
}


Expand Down
1 change: 1 addition & 0 deletions XADSimpleUnarchiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ XADEXPORT

-(XADError)parse;
-(XADError)_setupSubArchiveForEntryWithDataFork:(NSDictionary *)datadict resourceFork:(NSDictionary *)resourcedict;
-(BOOL)_setupSubArchiveForEntryWithDataFork:(NSDictionary *)datadict resourceFork:(NSDictionary *)resourcedict error:(NSError**)outError;

-(XADError)unarchive;
-(XADError)_unarchiveRegularArchive;
Expand Down
22 changes: 11 additions & 11 deletions XADSimpleUnarchiver.m
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ -(BOOL)parseWithError:(NSError**)error
{
if(entries.count) {
if (error) {
*error = [NSError errorWithDomain:XADErrorDomain code:XADErrorBadParameters userInfo:@{NSLocalizedDescriptionKey: @"You can not call parseAndUnarchive twice", NSDebugDescriptionErrorKey: @"You can not call parseAndUnarchive twice"}];
*error = [NSError errorWithDomain:XADErrorDomain code:XADErrorBadParameters userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"You can not call parseAndUnarchive twice", NSLocalizedDescriptionKey, nil]];
}

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

// Check if we have two entries, which are data and resource forks
// of the same archive.
if (entries.count==2) {
NSDictionary *first=entries[0];
NSDictionary *second=entries[1];
XADPath *name1=first[XADFileNameKey];
XADPath *name2=second[XADFileNameKey];
NSNumber *archnum1=first[XADIsArchiveKey];
NSNumber *archnum2=second[XADIsArchiveKey];
NSDictionary *first=[entries objectAtIndex:0];
NSDictionary *second=[entries objectAtIndex:1];
XADPath *name1=[first objectForKey:XADFileNameKey];
XADPath *name2=[second objectForKey:XADFileNameKey];
NSNumber *archnum1=[first objectForKey:XADIsArchiveKey];
NSNumber *archnum2=[second objectForKey:XADIsArchiveKey];
BOOL isarc1=archnum1&&archnum1.boolValue;
BOOL isarc2=archnum2&&archnum2.boolValue;

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

// TODO: Handle resource forks for archives that require them.
NSNumber *archnum=datafork[XADIsArchiveKey];
NSNumber *archnum=[datafork objectForKey:XADIsArchiveKey];
if(archnum&&archnum.boolValue) {
return [self _setupSubArchiveForEntryWithDataFork:datafork resourceFork:resourcefork error:error];
}
Expand Down
1 change: 1 addition & 0 deletions XADUnarchiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ nserror:(NSError **)errorptr;
-(XADError)_updateFileAttributesAtPath:(NSString *)path forEntryWithDictionary:(NSDictionary *)dict
deferDirectories:(BOOL)defer;
-(XADError)_ensureDirectoryExists:(NSString *)path;
-(BOOL)_ensureDirectoryExists:(NSString *)path error:(NSError**)outError;

-(XADError)runExtractorWithDictionary:(NSDictionary *)dict outputHandle:(CSHandle *)handle;
-(XADError)runExtractorWithDictionary:(NSDictionary *)dict
Expand Down
43 changes: 24 additions & 19 deletions XADUnarchiver.m
Original file line number Diff line number Diff line change
Expand Up @@ -324,16 +324,16 @@ -(XADError)extractEntryWithDictionary:(NSDictionary *)dict as:(NSString *)path f
}

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

NSNumber *dirnum=dict[XADIsDirectoryKey];
NSNumber *linknum=dict[XADIsLinkKey];
NSNumber *resnum=dict[XADIsResourceForkKey];
NSNumber *archivenum=dict[XADIsArchiveKey];
NSNumber *dirnum=[dict objectForKey:XADIsDirectoryKey];
NSNumber *linknum=[dict objectForKey:XADIsLinkKey];
NSNumber *resnum=[dict objectForKey:XADIsResourceForkKey];
NSNumber *archivenum=[dict objectForKey:XADIsArchiveKey];
BOOL isdir=dirnum&&dirnum.boolValue;
BOOL islink=linknum&&linknum.boolValue;
BOOL isres=resnum&&resnum.boolValue;
Expand All @@ -342,7 +342,7 @@ -(BOOL)extractEntryWithDictionary:(NSDictionary *)dict as:(nullable NSString *)p
// If we were not given a path, pick one ourselves.
if(!path)
{
XADPath *name=dict[XADFileNameKey];
XADPath *name=[dict objectForKey:XADFileNameKey];
NSString *namestring=name.sanitizedPathString;

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

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

// Attempt to extract embedded archives if requested.
Expand All @@ -377,6 +378,7 @@ -(BOOL)extractEntryWithDictionary:(NSDictionary *)dict as:(nullable NSString *)p
if([delegate unarchiver:self shouldExtractArchiveEntryWithDictionary:dict to:unarchiverpath])
{
okay=[self _extractArchiveEntryWithDictionary:dict to:unarchiverpath name:path.lastPathComponent error:&tmpErr];
[tmpErr retain];
// If extraction was attempted, and succeeded for failed, skip everything else.
// Otherwise, if the archive couldn't be opened, fall through and extract normally.
if(!okay && ([tmpErr.domain isEqualToString:XADErrorDomain] && tmpErr.code != XADErrorSubArchive)) goto end;
Expand All @@ -399,7 +401,7 @@ -(BOOL)extractEntryWithDictionary:(NSDictionary *)dict as:(nullable NSString *)p
tmpErr = nil;
} else {
okay = NO;
tmpErr = [NSError errorWithDomain:XADErrorDomain code:error userInfo:nil];
tmpErr = [[NSError alloc] initWithDomain:XADErrorDomain code:error userInfo:nil];
}
}
break;
Expand All @@ -413,7 +415,7 @@ -(BOOL)extractEntryWithDictionary:(NSDictionary *)dict as:(nullable NSString *)p
tmpErr = nil;
} else {
okay = NO;
tmpErr = [NSError errorWithDomain:XADErrorDomain code:error userInfo:nil];
tmpErr = [[NSError alloc] initWithDomain:XADErrorDomain code:error userInfo:nil];
}
}
break;
Expand Down Expand Up @@ -443,15 +445,15 @@ -(BOOL)extractEntryWithDictionary:(NSDictionary *)dict as:(nullable NSString *)p
tmpErr = nil;
} else {
okay = NO;
tmpErr = [NSError errorWithDomain:XADErrorDomain code:error userInfo:nil];
tmpErr = [[NSError alloc] initWithDomain:XADErrorDomain code:error userInfo:nil];
}
break;

default:
// TODO: better error
error=XADErrorBadParameters;
okay = NO;
tmpErr = [NSError errorWithDomain:XADErrorDomain code:XADErrorBadParameters userInfo:nil];
tmpErr = [[NSError alloc] initWithDomain:XADErrorDomain code:XADErrorBadParameters userInfo:nil];

break;
}
Expand Down Expand Up @@ -479,18 +481,21 @@ -(BOOL)extractEntryWithDictionary:(NSDictionary *)dict as:(nullable NSString *)p
tmpErr = nil;
} else {
okay = NO;
tmpErr = [NSError errorWithDomain:XADErrorDomain code:error userInfo:nil];
tmpErr = [[NSError alloc] initWithDomain:XADErrorDomain code:error userInfo:nil];
}

// Report success or failure
end:
if(delegate && [delegate respondsToSelector:@selector(unarchiver:didExtractEntryWithDictionary:to:error:)])
if([delegate respondsToSelector:@selector(unarchiver:didExtractEntryWithDictionary:to:error:)])
{
[delegate unarchiver:self didExtractEntryWithDictionary:dict to:path nserror:okay ? nil : tmpErr];
}
}
[pool release];

if (outErr && tmpErr) {
*outErr = tmpErr;
*outErr = [tmpErr autorelease];
} else if (tmpErr) {
[tmpErr release];
}

return okay;
Expand Down Expand Up @@ -877,7 +882,7 @@ -(XADError)_ensureDirectoryExists:(NSString *)path
if ([delegate respondsToSelector:@selector(unarchiver:didCreateDirectory:)]) {
[delegate unarchiver:self didCreateDirectory:path];
}
return XADNoError;
return XADErrorNone;
}
#endif
else return XADErrorMakeDirectory;
Expand Down Expand Up @@ -1029,7 +1034,7 @@ -(BOOL)runExtractorWithDictionary:(NSDictionary *)dict
}

// Try to find the size of this entry.
NSNumber *sizenum=dict[XADFileSizeKey];
NSNumber *sizenum=[dict objectForKey:XADFileSizeKey];
off_t size=0;
if(sizenum != nil)
{
Expand Down Expand Up @@ -1105,7 +1110,7 @@ -(BOOL)runExtractorWithDictionary:(NSDictionary *)dict

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

0 comments on commit d6d6e06

Please sign in to comment.