Compiler bug?
Compiler bug?
- Subject: Compiler bug?
- From: Murat Konar <email@hidden>
- Date: Tue, 13 Jul 2010 13:44:36 -0700
On Mac OS X 10.5.8, Xcode 3.1.3,
I ran into some very strange behavior today trying to get at the
extended attributes of files. In summary, for particular NSDictionary
object, the behavior of -objectForKey: is different, depending on what
other code runs.
I have distilled the weirdness into the code below.
------------------------------------------
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSDictionary* attrs = [[NSFileManager defaultManager]
attributesOfItemAtPath:
@"/some/file/with/finder/comment"
error:NULL];
NSLog(@"extAttrs:%@", [attrs
objectForKey:@"NSFileExtendedAttributes"]);
NSLog(@"attrs:%@", attrs);
NSLog(@"extAttrs:%@", [attrs
objectForKey:@"NSFileExtendedAttributes"]);
[pool drain];
return 0;
}
------------------------------------------
Note the three NSLog() statements. The first should output a
description of the extended attributes object in the dictionary
returned by the prior line. The second NSLog() outputs the attributes
dictionary itself. The third is an exact repeat of the first, and
should produce identical output, but it does not.
When run for a file with a Finder comment, this is the output (I
snipped the Finder comment data to prevent wrapping).
------------------------------------------
2010-07-13 13:14:30.648 FileManagerBug[9323:813] extAttrs:(null)
2010-07-13 13:14:30.653 FileManagerBug[9323:813] attrs:{
NSFileCreationDate = 2010-07-12 17:37:02 -0700;
NSFileExtendedAttributes = {
"com.apple.metadata:kMDItemFinderComment" =
<62706c69...00000e>;
};
NSFileExtensionHidden = 0;
NSFileGroupOwnerAccountID = 219;
NSFileGroupOwnerAccountName = gfx;
NSFileHFSCreatorCode = 0;
NSFileHFSTypeCode = 0;
NSFileModificationDate = 2010-07-12 17:37:02 -0700;
NSFileOwnerAccountID = 3779;
NSFileOwnerAccountName = murat;
NSFilePosixPermissions = 436;
NSFileReferenceCount = 1;
NSFileSize = 0;
NSFileSystemFileNumber = 17122047;
NSFileSystemNumber = 234881026;
NSFileType = NSFileTypeRegular;
}
2010-07-13 13:14:30.654 FileManagerBug[9323:813] extAttrs:{
"com.apple.metadata:kMDItemFinderComment" = <62706c69...00000e>;
}
Debugger stopped.
------------------------------------------
Note that the first NSLog() outputs "(null)", implying that [attrs
objectForKey:@"NSFileExtendedAttributes"] has returned nil. And yet
the second NSLog()'s output shows that indeed, an object with key
"NSFileExtendedAttributes" does exist in attrs. And weirdly, the third
NSLog()'s output, now confirms that there is an object in attrs with
key "NSFileExtendedAttributes".
WTF?
For those interested, you can download my test project from <http://bugs.muratnkonar.com/FileManagerBug.zip
>
_murat
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden