FYI: Bug in -getInfoForFile:application:type:
FYI: Bug in -getInfoForFile:application:type:
- Subject: FYI: Bug in -getInfoForFile:application:type:
- From: Lars Sonchocky-Helldorf <email@hidden>
- Date: Tue, 22 Jul 2003 03:57:16 +0200
The method -getInfoForFile:application:type: is not working as
documented. This is not a bug against the documentation, the documented
behavior is fine. The bug should be fixed in the sourcecode.
How to reproduce it:
compile and run the following program:
//
// GetInfoForFileBug.m
// getInfoForFile_bug
//
// Created by Lars Sonchocky-Helldorf on Thu Jul 17 2003.
// Copyright (c) 2003 __MyCompanyName__. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface GetInfoForFileBug : NSObject
{
NSWorkspace *workspace;
}
+ (GetInfoForFileBug *)new;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
- (void)logInfoForFile:(NSString *)path;
@end
@implementation GetInfoForFileBug
+ (GetInfoForFileBug *)new
{
return [[GetInfoForFileBug alloc] init];
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSString *path;
workspace = [NSWorkspace sharedWorkspace];
// plain file
path = @"/mach_kernel";
[self logInfoForFile: path];
// plain file
path = @"/private/var/db/volinfo.database";
[self logInfoForFile: path];
// plain file
path = @"/private/var/log/system.log";
[self logInfoForFile: path];
// directory
path = @"/usr/";
[self logInfoForFile: path];
// Application
path = @"/System/Library/CoreServices/Finder.app";
[self logInfoForFile: path];
// Filesystem *** ADJUST TO A VALUE VALID ON YOUR SYSTEM ***
path = @"/Volumes/Data/";
[self logInfoForFile: path];
// shell command
path = @"/usr/bin/man";
[self logInfoForFile: path];
NSLog(@"Values of NS*FileTypes are:\n NSPlainFileType: '%@'\n
NSDirectoryFileType: '%@'\n NSApplicationFileType: '%@'\n
NSFilesystemFileType: '%@'\n NSShellCommandFileType: '%@'\n",
NSPlainFileType,
NSDirectoryFileType,
NSApplicationFileType,
NSFilesystemFileType,
NSShellCommandFileType
);
}
- (void)logInfoForFile:(NSString *)path
{
NSString *app, *type;
[workspace getInfoForFile: path application: &app type: &type];
NSLog(@"path: '%@' is of type: '%@', application: '%@' is used to open
it\n", path, type, app);
if ([type isEqualToString: NSPlainFileType]) {
NSLog(@"type is equal to NSPlainFileType\n\n");
} else if ([type isEqualToString: NSDirectoryFileType]) {
NSLog(@"type is equal to NSDirectoryFileType\n\n");
} else if ([type isEqualToString: NSApplicationFileType]) {
NSLog(@"type is equal to NSApplicationFileType\n\n");
} else if ([type isEqualToString: NSFilesystemFileType]) {
NSLog(@"type is equal to NSFilesystemFileType\n\n");
} else if ([type isEqualToString: NSShellCommandFileType]) {
NSLog(@"type is equal to NSShellCommandFileType\n\n");
} else {
NSLog(@"type is not equal to any NS*FileType\n\n");
}
}
@end
int main(int argc, char **argv, char** env)
{
id pool = [NSAutoreleasePool new];
NSApplication *theApp = [NSApplication sharedApplication];
[theApp setDelegate: [GetInfoForFileBug new]];
[theApp run];
[pool release];
return 0;
}
the documentation (
http://developer.apple.com/documentation/Cocoa/Reference/
ApplicationKit/ObjC_classic/Classes/NSWorkspace.html#//apple_ref/doc/
uid/20000391/getInfoForFile_application_type_ ) says:
getInfoForFile:application:type:
- (BOOL)getInfoForFile:(NSString *)fullPath application:(NSString
**)appName type:(NSString **)type
Retrieves information about the file specified by fullPath. If this
method returns YES, the NSString pointed to by appName is set to the
application the system would use to open fullPath. The NSString pointed
to by type contains one of the values described in Constants.
This method returns NO if it could not find fullPath.
Description
NSPlainFileType
Plain (untyped) file
NSDirectoryFileType
Directory
NSApplicationFileType
Cocoa application
NSFilesystemFileType
File-system mount point
NSShellCommandFileType
Executable shell command
but if you run the program you'll get a result like this:
2003-07-17 05:53:48.335 getInfoForFile_bug[1742]
LSGetApplicationForURL() returned -10814 for file /mach_kernel.
2003-07-17 05:53:48.365 getInfoForFile_bug[1742] path: '/mach_kernel'
is of type: '', application: '(null)' is used to open it
2003-07-17 05:53:48.393 getInfoForFile_bug[1742] type is equal to
NSPlainFileType
2003-07-17 05:53:48.414 getInfoForFile_bug[1742]
LSGetApplicationForURL() returned -10814 for file
/private/var/db/volinfo.database.
2003-07-17 05:53:48.434 getInfoForFile_bug[1742] path:
'/private/var/db/volinfo.database' is of type: 'database', application:
'(null)' is used to open it
2003-07-17 05:53:48.461 getInfoForFile_bug[1742] type is not equal to
any NS*FileType
2003-07-17 05:53:48.487 getInfoForFile_bug[1742] path:
'/private/var/log/system.log' is of type: 'log', application:
'/Applications/Utilities/Console.app' is used to open it
2003-07-17 05:53:48.501 getInfoForFile_bug[1742] type is not equal to
any NS*FileType
2003-07-17 05:53:48.516 getInfoForFile_bug[1742] path: '/usr/' is of
type: '', application: '/System/Library/CoreServices/Finder.app' is
used to open it
2003-07-17 05:53:48.529 getInfoForFile_bug[1742] type is equal to
NSPlainFileType
2003-07-17 05:53:48.542 getInfoForFile_bug[1742] path:
'/System/Library/CoreServices/Finder.app' is of type: 'app',
application: '/System/Library/CoreServices/Finder.app' is used to open
it
2003-07-17 05:53:48.554 getInfoForFile_bug[1742] type is equal to
NSApplicationFileType
2003-07-17 05:53:48.566 getInfoForFile_bug[1742] path: '/Volumes/Data/'
is of type: '', application: '/System/Library/CoreServices/Finder.app'
is used to open it
2003-07-17 05:53:48.587 getInfoForFile_bug[1742] type is equal to
NSPlainFileType
2003-07-17 05:53:48.605 getInfoForFile_bug[1742]
LSGetApplicationForURL() returned -10814 for file /usr/bin/man.
2003-07-17 05:53:48.606 getInfoForFile_bug[1742] path: '/usr/bin/man'
is of type: '', application: '(null)' is used to open it
2003-07-17 05:53:48.606 getInfoForFile_bug[1742] type is equal to
NSPlainFileType
2003-07-17 05:53:48.606 getInfoForFile_bug[1742] Values of NS*FileTypes
are:
NSPlainFileType: ''
NSDirectoryFileType: 'NXDirectoryFileType'
NSApplicationFileType: 'app'
NSFilesystemFileType: 'NXFilesystemFileType'
NSShellCommandFileType: 'NXShellCommandFileType'
The most important thing to me is that I want to get
NXDirectoryFileType if I pass a directory to the message,
NXFilesystemFileType if I pass a path to a mounted volume and
NXShellCommandFileType if I pass the path of a shell command. Right now
those are all considered as plain file (NSPlainFileType). I understand
that currently for some reasons (unknown to me) the extension of a file
is returned as type. This is o.k. for me as long the three types
NXDirectoryFileType, NXFilesystemFileType and NXFilesystemFileType get
a special treatment. I would not mind if there would be even more
constants for instance NXLogFileType for the .log extension.
I filed this as bug radar 3337483
If you are also affected by this bug (or will be affected in a future
project) please file this bug too to show the importance of a fix for
this.
greetings, Lars
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.