--- ../cvsver/core/base/Source/NSUserDefaults.m 2004-02-10 13:17:10.000000000 +0800 +++ ../core/base/Source/NSUserDefaults.m 2004-01-20 23:05:28.000000000 +0800 @@ -239,7 +239,7 @@ * user ID. Needed by setuid processes which change the user they * are running as.
* In GNUstep you should call GSSetUserName() when changing your - * effective user ID, and that class will call this function for you. + * effective user ID, and that function will call this function for you. */ + (void) resetStandardUserDefaults { @@ -613,25 +613,22 @@ return [self initWithUser: NSUserName()]; } +/* Returns the path to the user's ".GNUstepDefaults file" */ static NSString *pathForUser(NSString *user) { NSString *database = @".GNUstepDefaults"; NSFileManager *mgr = [NSFileManager defaultManager]; - NSString *home; NSString *path; - NSString *old; unsigned desired; NSDictionary *attr; BOOL isDir; - home = GSDefaultsRootForUser(user); - if (home == nil) + path = GSDefaultsRootForUser(user); + if (path == nil) { - /* Probably on MINGW. Where to put it? */ - NSLog(@"Could not get user root. Using NSOpenStepRootDirectory()"); - home = NSOpenStepRootDirectory(); + return [NSSearchPathForDirectoriesInDomains(NSUserDirectory, + NSUserDomainMask, YES) lastObject]; } - path = [home stringByAppendingPathComponent: @"Defaults"]; #if !(defined(S_IRUSR) && defined(S_IWUSR) && defined(S_IXUSR) \ && defined(S_IRGRP) && defined(S_IXGRP) \ @@ -645,80 +642,28 @@ [NSNumberClass numberWithUnsignedLong: desired], NSFilePosixPermissions, nil]; - if ([mgr fileExistsAtPath: home isDirectory: &isDir] == NO) - { - if ([mgr createDirectoryAtPath: home attributes: attr] == NO) - { - NSLog(@"Defaults home '%@' does not exist - failed to create it.", - home); - return nil; - } - else - { - NSLog(@"Defaults home '%@' did not exist - created it", home); - isDir = YES; - } - } - if (isDir == NO) - { - NSLog(@"ERROR - defaults home '%@' is not a directory!", home); - return nil; - } - if ([mgr fileExistsAtPath: path isDirectory: &isDir] == NO) { if ([mgr createDirectoryAtPath: path attributes: attr] == NO) - { - NSLog(@"Defaults path '%@' does not exist - failed to create it.", - path); - return nil; - } + { + NSLog(@"Defaults home '%@' does not exist - failed to create it.", + path); + return nil; + } else - { - NSLog(@"Defaults path '%@' did not exist - created it", path); - isDir = YES; - } + { + NSLog(@"Defaults home '%@' did not exist - created it", path); + isDir = YES; + } } if (isDir == NO) { - NSLog(@"ERROR - Defaults path '%@' is not a directory!", path); + NSLog(@"ERROR - defaults home '%@' is not a directory!", path); return nil; } +// NSLog(@"Determined Defaults home to be '%@'\n",path); path = [path stringByAppendingPathComponent: database]; - old = [home stringByAppendingPathComponent: database]; - if ([mgr fileExistsAtPath: path] == NO) - { - if ([mgr fileExistsAtPath: old] == YES) - { - if ([mgr movePath: old toPath: path handler: nil] == YES) - { - NSLog(@"Moved defaults database from old location (%@) to %@", - old, path); - } - } - } - if ([mgr fileExistsAtPath: old] == YES) - { - NSLog(@"Warning - ignoring old defaults database in %@", old); - } - - /* - * Try to create standard directory hierarchy if necessary - */ - home = [NSSearchPathForDirectoriesInDomains(NSUserDirectory, - NSUserDomainMask, YES) lastObject]; - if (home != nil) - { - NSString *p; - - p = [home stringByAppendingPathComponent: @"Library"]; - if ([mgr fileExistsAtPath: p isDirectory: &isDir] == NO) - { - [mgr createDirectoryAtPath: p attributes: attr]; - } - } - return path; } @@ -1431,7 +1376,7 @@ { NSLog(@"Creating defaults database file %@", _defaultsDatabase); [newDict writeToFile: _defaultsDatabase atomically: YES]; - attr = [mgr fileAttributesAtPath: _defaultsDatabase + attr = [mgr fileAttributesAtPath: _defaultsDatabase traverseLink: YES]; } } @@ -1452,6 +1397,7 @@ } } +#ifdef OPTION_ENFORCE_DEFAULTS_PERMS /* * We enforce the permission mode 0600 on the defaults database */ @@ -1476,6 +1422,7 @@ [mgr changeFileAttributes: enforced_attributes atPath: _defaultsDatabase]; } +#endif // OPTION_ENFORCE_DEFAULTS_PERMS if (_changedDomains != nil) { // Synchronize both dictionaries