Skip to content

Commit

Permalink
Fix code for renaming old (process name) defaults to new (bundle iden…
Browse files Browse the repository at this point in the history
…tifier).
  • Loading branch information
rfm committed Dec 31, 2024
1 parent 5d7018a commit 3120a1e
Showing 1 changed file with 35 additions and 33 deletions.
68 changes: 35 additions & 33 deletions Source/NSUserDefaults.m
Original file line number Diff line number Diff line change
Expand Up @@ -1951,17 +1951,17 @@ - (id) valueForKey: (NSString*)aKey

- (BOOL) wantToReadDefaultsSince: (NSDate*)lastSyncDate
{
NSFileManager *mgr;
NSDictionary *attr;

mgr = [NSFileManager defaultManager];
attr = [mgr fileAttributesAtPath: _defaultsDatabase traverseLink: YES];
if (lastSyncDate == nil)
if (nil == lastSyncDate)
{
return YES;
}
else
{
NSFileManager *mgr;
NSDictionary *attr;

mgr = [NSFileManager defaultManager];
attr = [mgr fileAttributesAtPath: _defaultsDatabase traverseLink: YES];
if (attr == nil)
{
return YES;
Expand Down Expand Up @@ -2615,11 +2615,35 @@ - (BOOL) _lockDefaultsFile: (BOOL*)wasLocked

- (BOOL) _readDefaults
{
NSEnumerator *enumerator;
NSString *domainName;
BOOL haveChange = NO;
NSFileManager *mgr = [NSFileManager defaultManager];
NSEnumerator *enumerator;
NSString *domainName;
BOOL haveChange = NO;
static BOOL beenHere = NO;

if (NO == beenHere)
{
NSString *npath = _defaultsDatabase;
NSString *opath = _defaultsDatabase;

beenHere = YES;
/* The default domain name for a program changed from being the name
* of the executable to being the bundle identifier (if available).
* If the domain file does not exist for the new name but does exist
* for the old name, we move the file to the modern location.
*/
opath = [npath stringByAppendingPathComponent: processName];
opath = [opath stringByAppendingPathExtension: @"plist"];
npath = [npath stringByAppendingPathComponent: bundleIdentifier];
npath = [npath stringByAppendingPathExtension: @"plist"];
if (NO == [mgr isReadableFileAtPath: npath]
&& YES == [mgr isReadableFileAtPath: opath])
{
[mgr movePath: opath toPath: npath handler: nil];
}
}

enumerator = [[[NSFileManager defaultManager]
enumerator = [[mgr
directoryContentsAtPath: _defaultsDatabase] objectEnumerator];
while (nil != (domainName = [enumerator nextObject]))
{
Expand Down Expand Up @@ -2875,32 +2899,10 @@ - (BOOL) synchronize
{
NSFileManager *mgr;
NSMutableDictionary *disk;
BOOL found;

mgr = [NSFileManager defaultManager];
disk = nil;
found = [mgr isReadableFileAtPath: path];

/* The default domain name for a program changed from being the name
* of the executable to being the bundle identifier (if available).
* If the domain file does not exist for the new name but does exist
* for the old name, we move the file to the modern location.
*/
if (NO == found
&& [name isEqual: bundleIdentifier]
&& NO == [name isEqual: processName])
{
NSString *pp = [owner _directory];

pp = [pp stringByAppendingPathComponent: processName];
pp = [pp stringByAppendingPathExtension: @"plist"];
if ([mgr isReadableFileAtPath: pp])
{
found = [mgr movePath: pp toPath: path handler: nil];
}
}

if (found)
if ([mgr isReadableFileAtPath: path])
{
NSData *data;

Expand Down

0 comments on commit 3120a1e

Please sign in to comment.