Permalink
Browse files

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.
  • Loading branch information...
andymatuschak committed Jul 17, 2008
1 parent b815ce9 commit 58a05e2ee7bb8dc254c4f3ddf6fa35b9273a50c7
Showing with 23 additions and 47 deletions.
  1. +1 −1 SUBasicUpdateDriver.m
  2. +2 −3 SUDiskImageUnarchiver.m
  3. +9 −11 SUPipedUnarchiver.m
  4. +2 −2 SUUnarchiver.h
  5. +3 −3 SUUnarchiver.m
  6. +2 −6 SUUnarchiver_Private.h
  7. +4 −21 SUUnarchiver_Private.m
View
@@ -179,7 +179,7 @@ - (void)extractUpdate
}
}
- SUUnarchiver *unarchiver = [SUUnarchiver unarchiverForURL:[[[NSURL alloc] initFileURLWithPath:downloadPath] autorelease]];
+ SUUnarchiver *unarchiver = [SUUnarchiver unarchiverForPath:downloadPath];
if (!unarchiver)
{
NSLog(@"Sparkle Error: No valid unarchiver for %@!", downloadPath);
View
@@ -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)start
- (void)_extractDMG
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- NSString *archivePath = [archiveURL path];
BOOL mountedSuccessfully = NO;
// get a unique mount point path
View
@@ -11,41 +11,39 @@
@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;
}
- (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.
View
@@ -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;
View
@@ -15,14 +15,14 @@ @implementation SUUnarchiver
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;
}
View
@@ -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
View
@@ -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 @@ + (NSArray *)_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

0 comments on commit 58a05e2

Please sign in to comment.