diff --git a/ChangeLog b/ChangeLog index 364f23a6c..7be939cef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2011-12-17 Richard Frith-Macdonald + + * Source/NSUserDefaults.m: + Whenever we synchronize in a state where we have changes to write, + but are in read-only mode (no database existed on startup, or we + couldn't create the lock file on startup), check to see if the + database is now writable (we can create the lock file). + Should fix problem where new defaults files were not getting created. + 2011-12-15 Richard Frith-Macdonald * Source/NSProcessInfo.m: diff --git a/Source/NSUserDefaults.m b/Source/NSUserDefaults.m index 462943344..80c55b90c 100644 --- a/Source/NSUserDefaults.m +++ b/Source/NSUserDefaults.m @@ -1724,10 +1724,6 @@ static BOOL isPlistObject(id o) NSFileManager *mgr; NSDictionary *attr; - if (nil == _fileLock) - { - return NO; // Database did not exist on startup. - } mgr = [NSFileManager defaultManager]; attr = [mgr fileAttributesAtPath: _defaultsDatabase traverseLink: YES]; if (lastSyncDate == nil) @@ -1776,7 +1772,18 @@ static BOOL isPlistObject(id o) if (_changedDomains != nil || YES == [self wantToReadDefaultsSince: saved]) { - DESTROY(_dictionaryRep); + /* If we want to write but are currently read-only, try to + * create the path to make things writable. + */ + if (_changedDomains != nil && YES == [self _readOnly]) + { + NSString *path = lockPath(_defaultsDatabase, NO); + + if (nil != path) + { + _fileLock = [[NSDistributedLock alloc] initWithPath: path]; + } + } if ([self _lockDefaultsFile: &wasLocked] == NO) { result = NO; @@ -1788,10 +1795,14 @@ static BOOL isPlistObject(id o) NSFileManager *mgr; haveNewDomain = [self _readDefaults]; + if (YES == haveNewDomain) + { + DESTROY(_dictionaryRep); + } mgr = [NSFileManager defaultManager]; - if (_changedDomains != nil) + if (_changedDomains != nil && NO == [self _readOnly]) { GSPersistentDomain *domain;