On Jul 28, 2009, at 9:56 PM, Andy Lee wrote:
On Jul 28, 2009, at 7:54 PM, Seth Willits wrote:
It works its way down to the last if statement which launches /usr/ bin/file to figure out the type of the file. It's all straight forward simple code, which simply returns YES or NO, but it's causing an exception apparently, and I don't see how I could do anything different.
Offhand it all looks pretty innocuous to me, but regarding that last  
part -- is fileTypeForFileAtPath: a category method you added?  If  
so, can you show the code?

Yes. It just fires off a task.


- (NSString *)fileTypeForFileAtPath:(NSString *)filePath;
{
        NSPipe * pipe = [[NSPipe alloc] init];
        NSTask * task = [[NSTask alloc] init];
        NSString * result;
        NSData * data;
        
        
        [task setLaunchPath:@"/usr/bin/file"];
        [task setArguments:[NSArray arrayWithObjects:@"-b", filePath, nil]];
        [task setStandardOutput:pipe];
        [task launch];
        [task waitUntilExit];
        
        if ([task terminationStatus] != 0) {
                result = nil;
                goto bail;
        }
        
        data = [[pipe fileHandleForReading] availableData];
        if (data == nil) {
                result = nil;
                goto bail;
        }
                
result = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
        
bail:
        [pipe release];
        [task release];
        return result;
}



I'd file a bug report on the exception being thrown, but heck if I can reproduce it.

--
Seth Willits



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to