Re: [SOLVED] createDirectoryAtPath anomaly between system versions?
Re: [SOLVED] createDirectoryAtPath anomaly between system versions?
- Subject: Re: [SOLVED] createDirectoryAtPath anomaly between system versions?
- From: Antonio Nunes <email@hidden>
- Date: Fri, 7 Jul 2006 11:35:47 +0100
On 5 Jul 2006, at 10:47, Antonio Nunes wrote:
Is anybody aware of a change/bug-fix somewhere between 10.4.3 and
10.4.7 where creating a directory in applicationWillFinishLaunching
works in 10.4.7 but not in 10.4.3?
Ok, I created a minimal test app, and the problem also showed up in
10.4.7, and it turns out I was mistaken about where exactly things
were going wrong:
-Created a document based Cocoa app
-Created a class to be a delegate of the application object
-Connected the delegate in IB
-Added the following code to the delegate:
@implementation ANAppController
- (void)applicationWillFinishLaunching:(NSNotification *)aNotification
{
BOOL isDir, exists = NO, success = NO;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *myAppDirectoryPath = nil;
NSArray *paths = NSSearchPathForDirectoriesInDomains
(NSApplicationSupportDirectory, NSLocalDomainMask, YES);
if ([paths count] > 0) {
myAppDirectoryPath = [[paths objectAtIndex:0]
stringByAppendingPathComponent:@"MySupportFolderTestApp"];
exists = [fileManager fileExistsAtPath:myAppDirectoryPath
isDirectory:&isDir];
if (!isDir) {
success = [fileManager createDirectoryAtPath:myAppDirectoryPath
attributes:nil];
if (!success) {
[...]
}
} // if (!isDir)
} else {
[...]
} // if ([paths count] > 0)
}
@end
-Run the code in debug configuration and it works. Run it in release
configuration and createDirectoryAtPath is never reached, which
explains why the directory isn't created.
-Changing
if (!isDir) {
to
if (!exists || !isDir) {
(which is conceptually more correct anyway) fixes this to work in
release configuration builds too.
But I don't see why the former code would work in one configuration
and not in another. Does anybody have any ideas? Why would the local
variable isDir behave differently in the different build
configurations? Should I file this as a bug with Apple?
Kind regards,
António
-----------------------------------------
Accepting others as they are
brings a wonderful freedom
to your own mind.
--The Peace Formula
-----------------------------------------
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden