repaired user defaults stuff and added symbolic link fix

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@10179 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2001-06-15 08:49:03 +00:00
parent a80667c989
commit e73e95fca3
4 changed files with 77 additions and 17 deletions

View file

@ -1,3 +1,19 @@
2001-06-15 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSuserDefaults.m: Fix +resetUserDefaults to retain the
NSRegistrationDomain information ... was losing it when this method
was called in response to the user name being initially set.
([-registerDefaults:]) fix for when no dictionary found.
Use NSLanguages rather than Languages as key for the languages list.
* Source/NSUser.m: GSSetUserName() ... only reset the user defaults
if the name is actually changed - and not if it is being initialised.
When standardUserDefaults are first obtained, the user name should be
initialised as part of that process anyway.
* Source/NSFileManager.m: ([-removeFileAtpath:handler:])
Fix this method so it *doesn't* follow symbolic links.
This makes it conform to the documentation and prevents
accidental removal of entire directory hierarchies!
Wed Jun 13 19:43:16 2001 Nicola Pero <n.pero@mi.flashnet.it>
* Source/NSFileManager.m

View file

@ -538,19 +538,42 @@ static NSFileManager* defaultManager = nil;
- (BOOL) removeFileAtPath: (NSString*)path
handler: handler
{
BOOL exists, is_dir;
BOOL is_dir;
const char *cpath;
if (handler != nil)
[handler fileManager: self willProcessPath: path];
exists = [self fileExistsAtPath: path isDirectory: &is_dir];
if (!exists)
return NO;
cpath = [self fileSystemRepresentationWithPath: path];
if (cpath == 0 || *cpath == '\0')
{
return NO;
}
else
{
#if defined(__MINGW__)
DWORD res;
res = GetFileAttributes(cpath);
if (res == WIN32ERR)
return NO;
if (res & FILE_ATTRIBUTE_DIRECTORY)
is_dir = YES;
else
is_dir = NO;
#else
struct stat statbuf;
if (lstat(cpath, &statbuf) != 0)
return NO;
is_dir = ((statbuf.st_mode & S_IFMT) == S_IFDIR);
#endif /* MINGW */
}
if (!is_dir)
{
const char *cpath = [path fileSystemRepresentation];
#if defined(__MINGW__)
if (DeleteFile(cpath) == FALSE)
#else
@ -565,7 +588,8 @@ static NSFileManager* defaultManager = nil;
info = [[NSMutableDictionary alloc] initWithCapacity: 3];
[info setObject: path forKey: @"Path"];
[info setObject: [NSString stringWithCString: GSLastErrorStr(errno)]
[info setObject: [NSString stringWithCString:
GSLastErrorStr(errno)]
forKey: @"Error"];
result = [handler fileManager: self
shouldProceedAfterError: info];
@ -609,7 +633,8 @@ static NSFileManager* defaultManager = nil;
info = [[NSMutableDictionary alloc] initWithCapacity: 3];
[info setObject: path forKey: @"Path"];
[info setObject: [NSString stringWithCString: GSLastErrorStr(errno)]
[info setObject: [NSString stringWithCString:
GSLastErrorStr(errno)]
forKey: @"Error"];
result = [handler fileManager: self
shouldProceedAfterError: info];
@ -1415,7 +1440,7 @@ static SEL swfsSel = 0;
else
{
NSLog(@"Failed to recurse into directory '%@' - %s",
path, GSLastErrorStr(errno));
path, GSLastErrorStr(errno));
}
return self;
@ -1555,7 +1580,7 @@ static SEL swfsSel = 0;
else
{
NSLog(@"Failed to recurse into directory '%s' - %s",
_current_file_path, GSLastErrorStr(errno));
_current_file_path, GSLastErrorStr(errno));
}
}
}

View file

@ -58,8 +58,8 @@ GSSetUserName(NSString* name)
else if ([theUserName isEqualToString: name] == NO)
{
ASSIGN(theUserName, name);
[NSUserDefaults resetUserDefaults];
}
[NSUserDefaults resetUserDefaults];
}
/*

View file

@ -106,8 +106,25 @@ static BOOL setSharedDefaults = NO; /* Flag to prevent infinite recursion */
+ (void) resetUserDefaults
{
setSharedDefaults = NO;
DESTROY(sharedDefaults);
if (sharedDefaults != nil)
{
NSDictionary *regDefs;
regDefs = RETAIN([sharedDefaults->_tempDomains
objectForKey: NSRegistrationDomain]);
setSharedDefaults = NO;
DESTROY(sharedDefaults);
if (regDefs != nil)
{
[self standardUserDefaults];
if (sharedDefaults != nil)
{
[sharedDefaults->_tempDomains setObject: regDefs
forKey: NSRegistrationDomain];
}
RELEASE(regDefs);
}
}
}
/* Create a locale dictionary when we have absolutely no information
@ -308,7 +325,7 @@ static BOOL setSharedDefaults = NO; /* Flag to prevent infinite recursion */
locale = GSSetLocale(@"");
if (sharedDefaults == nil)
{
/* Create our own defaults to get "Languages" since sharedDefaults
/* Create our own defaults to get "NSLanguages" since sharedDefaults
depends on us */
NSUserDefaults *tempDefaults;
@ -328,13 +345,14 @@ static BOOL setSharedDefaults = NO; /* Flag to prevent infinite recursion */
[sList addObject: NSRegistrationDomain];
[tempDefaults setSearchList: sList];
RELEASE(sList);
currLang = [tempDefaults stringArrayForKey: @"Languages"];
currLang = [tempDefaults stringArrayForKey: @"NSLanguages"];
AUTORELEASE(tempDefaults);
}
}
else
{
currLang = [[self standardUserDefaults] stringArrayForKey: @"Languages"];
currLang
= [[self standardUserDefaults] stringArrayForKey: @"NSLanguages"];
}
if (currLang == nil && locale != 0 && GSLanguageFromLocale(locale))
{
@ -880,7 +898,7 @@ static NSString *pathForUser(NSString *user)
else
{
attr = [NSDictionary dictionaryWithObjectsAndKeys:
NSUserName(), NSFileOwnerAccountName, nil];
NSUserName(), NSFileOwnerAccountName, nil];
NSLog(@"Creating defaults database file %@", _defaultsDatabase);
[mgr createFileAtPath: _defaultsDatabase
contents: nil
@ -1034,6 +1052,7 @@ static NSString *pathForUser(NSString *user)
{
regDefs = [NSMutableDictionaryClass
dictionaryWithCapacity: [newVals count]];
[_tempDomains setObject: regDefs forKey: NSRegistrationDomain];
}
DESTROY(_dictionaryRep);
[regDefs addEntriesFromDictionary: newVals];