From 58a05e2ee7bb8dc254c4f3ddf6fa35b9273a50c7 Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Wed, 16 Jul 2008 22:48:10 -0700 Subject: [PATCH] Fixes 243533 (for real this time, I hope) I've undone all the UTI nonsense: I don't see any reason to use it if the underlying frameworks are just going to do dumber path extension comparison that what I'm already doing. I've switched back to the tried-and-true method. I also made SUUnarchiver* path-based instead of NSURL-based because I realized that the latter didn't make any sense given that we're only unarchiving local files. --- SUBasicUpdateDriver.m | 2 +- SUDiskImageUnarchiver.m | 5 ++--- SUPipedUnarchiver.m | 20 +++++++++----------- SUUnarchiver.h | 4 ++-- SUUnarchiver.m | 6 +++--- SUUnarchiver_Private.h | 8 ++------ SUUnarchiver_Private.m | 25 ++++--------------------- 7 files changed, 23 insertions(+), 47 deletions(-) diff --git a/SUBasicUpdateDriver.m b/SUBasicUpdateDriver.m index 769358c9..cd08443b 100644 --- a/SUBasicUpdateDriver.m +++ b/SUBasicUpdateDriver.m @@ -179,7 +179,7 @@ } } - SUUnarchiver *unarchiver = [SUUnarchiver unarchiverForURL:[[[NSURL alloc] initFileURLWithPath:downloadPath] autorelease]]; + SUUnarchiver *unarchiver = [SUUnarchiver unarchiverForPath:downloadPath]; if (!unarchiver) { NSLog(@"Sparkle Error: No valid unarchiver for %@!", downloadPath); diff --git a/SUDiskImageUnarchiver.m b/SUDiskImageUnarchiver.m index 5ec29aa0..65ba8921 100644 --- a/SUDiskImageUnarchiver.m +++ b/SUDiskImageUnarchiver.m @@ -12,9 +12,9 @@ @implementation SUDiskImageUnarchiver -+ (BOOL)_canUnarchiveURL:(NSURL *)URL ++ (BOOL)_canUnarchivePath:(NSString *)path { - return [URL conformsToType:@"public.disk-image"]; + return [[path pathExtension] isEqualToString:@"dmg"]; } - (void)start @@ -25,7 +25,6 @@ - (void)_extractDMG { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSString *archivePath = [archiveURL path]; BOOL mountedSuccessfully = NO; // get a unique mount point path diff --git a/SUPipedUnarchiver.m b/SUPipedUnarchiver.m index e058f926..0c691e09 100644 --- a/SUPipedUnarchiver.m +++ b/SUPipedUnarchiver.m @@ -11,21 +11,20 @@ @implementation SUPipedUnarchiver -+ (SEL)_selectorConformingToTypeOfURL:(NSURL *)URL ++ (SEL)_selectorConformingToTypeOfPath:(NSString *)path { static NSDictionary *typeSelectorDictionary; - // HACK: The UTI detector is dumb (not my fault!) and sees .tar.gz files as plain .gz files. If we see something of type .bz2 or .gz, we'll assume it's really a .tar.bz2 or .tar.gz. if (!typeSelectorDictionary) - typeSelectorDictionary = [[NSDictionary dictionaryWithObjectsAndKeys:@"_extractZIP", @"com.pkware.zip-archive", - @"_extractTGZ", @"org.gnu.gnu-zip-tar-archive", @"_extractTGZ", @"org.gnu.gnu-zip-archive", - @"_extractTBZ", @"org.bzip.bzip2-tar-archive", @"_extractTBZ", @"org.bzip.bzip2-archive", @"_extractTBZ", @"public.archive.bzip2", - @"_extractTAR", @"public.tar-archive", nil] retain]; + typeSelectorDictionary = [[NSDictionary dictionaryWithObjectsAndKeys:@"_extractZIP", @".zip", @"_extractTAR", @".tar", + @"_extractTGZ", @".tar.gz", @"_extractTGZ", @".tgz", + @"_extractTBZ", @".tar.bz2", @"_extractTBZ", @".tbz", nil] retain]; + NSString *lastPathComponent = [path lastPathComponent]; NSEnumerator *typeEnumerator = [typeSelectorDictionary keyEnumerator]; id currentType; while ((currentType = [typeEnumerator nextObject])) { - if ([URL conformsToType:currentType]) + if ([[lastPathComponent substringFromIndex:[lastPathComponent length] - [currentType length]] isEqualToString:currentType]) return NSSelectorFromString([typeSelectorDictionary objectForKey:currentType]); } return NULL; @@ -33,19 +32,18 @@ - (void)start { - [NSThread detachNewThreadSelector:[[self class] _selectorConformingToTypeOfURL:archiveURL] toTarget:self withObject:nil]; + [NSThread detachNewThreadSelector:[[self class] _selectorConformingToTypeOfPath:archivePath] toTarget:self withObject:nil]; } -+ (BOOL)_canUnarchiveURL:(NSURL *)URL ++ (BOOL)_canUnarchivePath:(NSString *)path { - return ([self _selectorConformingToTypeOfURL:URL] != nil); + return ([self _selectorConformingToTypeOfPath:path] != nil); } // This method abstracts the types that use a command line tool piping data from stdin. - (void)_extractArchivePipingDataToCommand:(NSString *)command { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSString *archivePath = [archiveURL path]; FILE *fp = NULL, *cmdFP = NULL; // Get the file size. diff --git a/SUUnarchiver.h b/SUUnarchiver.h index 8b1325c4..1b237210 100644 --- a/SUUnarchiver.h +++ b/SUUnarchiver.h @@ -11,10 +11,10 @@ @interface SUUnarchiver : NSObject { id delegate; - NSURL *archiveURL; + NSString *archivePath; } -+ (SUUnarchiver *)unarchiverForURL:(NSURL *)URL; ++ (SUUnarchiver *)unarchiverForPath:(NSString *)path; - (void)setDelegate:delegate; - (void)start; diff --git a/SUUnarchiver.m b/SUUnarchiver.m index 77fed4ac..9d1ee354 100644 --- a/SUUnarchiver.m +++ b/SUUnarchiver.m @@ -15,14 +15,14 @@ extern NSMutableArray *__unarchiverImplementations; -+ (SUUnarchiver *)unarchiverForURL:(NSURL *)URL ++ (SUUnarchiver *)unarchiverForPath:(NSString *)path { NSEnumerator *implementationEnumerator = [[self _unarchiverImplementations] objectEnumerator]; id current; while ((current = [implementationEnumerator nextObject])) { - if ([current _canUnarchiveURL:URL]) - return [[[current alloc] _initWithURL:URL] autorelease]; + if ([current _canUnarchivePath:path]) + return [[[current alloc] _initWithPath:path] autorelease]; } return nil; } diff --git a/SUUnarchiver_Private.h b/SUUnarchiver_Private.h index bae20e53..acf620ac 100644 --- a/SUUnarchiver_Private.h +++ b/SUUnarchiver_Private.h @@ -15,16 +15,12 @@ @interface SUUnarchiver (Private) + (void)_registerImplementation:(Class)implementation; + (NSArray *)_unarchiverImplementations; -+ (BOOL)_canUnarchiveURL:(NSURL *)URL; -- _initWithURL:(NSURL *)URL; ++ (BOOL)_canUnarchivePath:(NSString *)path; +- _initWithPath:(NSString *)path; - (void)_notifyDelegateOfExtractedLength:(long)length; - (void)_notifyDelegateOfSuccess; - (void)_notifyDelegateOfFailure; @end -@interface NSURL (SUTypeDetection) -- (BOOL)conformsToType:(NSString *)type; -@end - #endif diff --git a/SUUnarchiver_Private.m b/SUUnarchiver_Private.m index a705a0ac..26105085 100644 --- a/SUUnarchiver_Private.m +++ b/SUUnarchiver_Private.m @@ -10,20 +10,20 @@ @implementation SUUnarchiver (Private) -- _initWithURL:(NSURL *)URL +- _initWithPath:(NSString *)path { if ((self = [super init])) - archiveURL = [URL copy]; + archivePath = [path copy]; return self; } - (void)dealloc { - [archiveURL release]; + [archivePath release]; [super dealloc]; } -+ (BOOL)_canUnarchiveURL:(NSURL *)URL ++ (BOOL)_canUnarchivePath:(NSString *)path { return NO; } @@ -61,20 +61,3 @@ static NSMutableArray *__unarchiverImplementations; } @end - -@implementation NSURL (SUTypeDetection) -- (NSString *)__UTI -{ - FSRef fsRefToItem; - FSPathMakeRef((UInt8 *)[[self path] fileSystemRepresentation], &fsRefToItem, NULL ); - - NSString *UTI = nil; - LSCopyItemAttribute(&fsRefToItem, kLSRolesAll, kLSItemContentType, (CFTypeRef *)(&UTI)); - return [UTI autorelease]; -} - -- (BOOL)conformsToType:(NSString *)type -{ - return UTTypeConformsTo((CFStringRef)[self __UTI], (CFStringRef)type); -} -@end