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:
CaS 2001-06-15 08:49:03 +00:00
parent 5ab89c7a6b
commit 2d1e8debbb
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> Wed Jun 13 19:43:16 2001 Nicola Pero <n.pero@mi.flashnet.it>
* Source/NSFileManager.m * Source/NSFileManager.m

View file

@ -538,19 +538,42 @@ static NSFileManager* defaultManager = nil;
- (BOOL) removeFileAtPath: (NSString*)path - (BOOL) removeFileAtPath: (NSString*)path
handler: handler handler: handler
{ {
BOOL exists, is_dir; BOOL is_dir;
const char *cpath;
if (handler != nil) if (handler != nil)
[handler fileManager: self willProcessPath: path]; [handler fileManager: self willProcessPath: path];
exists = [self fileExistsAtPath: path isDirectory: &is_dir]; cpath = [self fileSystemRepresentationWithPath: path];
if (!exists) if (cpath == 0 || *cpath == '\0')
return NO; {
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) if (!is_dir)
{ {
const char *cpath = [path fileSystemRepresentation];
#if defined(__MINGW__) #if defined(__MINGW__)
if (DeleteFile(cpath) == FALSE) if (DeleteFile(cpath) == FALSE)
#else #else
@ -565,7 +588,8 @@ static NSFileManager* defaultManager = nil;
info = [[NSMutableDictionary alloc] initWithCapacity: 3]; info = [[NSMutableDictionary alloc] initWithCapacity: 3];
[info setObject: path forKey: @"Path"]; [info setObject: path forKey: @"Path"];
[info setObject: [NSString stringWithCString: GSLastErrorStr(errno)] [info setObject: [NSString stringWithCString:
GSLastErrorStr(errno)]
forKey: @"Error"]; forKey: @"Error"];
result = [handler fileManager: self result = [handler fileManager: self
shouldProceedAfterError: info]; shouldProceedAfterError: info];
@ -609,7 +633,8 @@ static NSFileManager* defaultManager = nil;
info = [[NSMutableDictionary alloc] initWithCapacity: 3]; info = [[NSMutableDictionary alloc] initWithCapacity: 3];
[info setObject: path forKey: @"Path"]; [info setObject: path forKey: @"Path"];
[info setObject: [NSString stringWithCString: GSLastErrorStr(errno)] [info setObject: [NSString stringWithCString:
GSLastErrorStr(errno)]
forKey: @"Error"]; forKey: @"Error"];
result = [handler fileManager: self result = [handler fileManager: self
shouldProceedAfterError: info]; shouldProceedAfterError: info];
@ -1415,7 +1440,7 @@ static SEL swfsSel = 0;
else else
{ {
NSLog(@"Failed to recurse into directory '%@' - %s", NSLog(@"Failed to recurse into directory '%@' - %s",
path, GSLastErrorStr(errno)); path, GSLastErrorStr(errno));
} }
return self; return self;
@ -1555,7 +1580,7 @@ static SEL swfsSel = 0;
else else
{ {
NSLog(@"Failed to recurse into directory '%s' - %s", 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) else if ([theUserName isEqualToString: name] == NO)
{ {
ASSIGN(theUserName, name); ASSIGN(theUserName, name);
[NSUserDefaults resetUserDefaults];
} }
[NSUserDefaults resetUserDefaults];
} }
/* /*

View file

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