diff --git a/CoreFoundation/Preferences.subproj/CFXMLPreferencesDomain.c b/CoreFoundation/Preferences.subproj/CFXMLPreferencesDomain.c index c7a87de559..1b98874c62 100644 --- a/CoreFoundation/Preferences.subproj/CFXMLPreferencesDomain.c +++ b/CoreFoundation/Preferences.subproj/CFXMLPreferencesDomain.c @@ -273,6 +273,10 @@ static Boolean __CFWriteBytesToFileWithAtomicity(CFURLRef url, const void *bytes close(fd); if (atomic) { + // If the file was renamed successfully and we wrote it as root we need to reset the owner & group as they were. + if (writingFileAsRoot) { + chown(auxPath, owner, group); + } // preserve the mode as passed in originally chmod(auxPath, mode); @@ -280,11 +284,6 @@ static Boolean __CFWriteBytesToFileWithAtomicity(CFURLRef url, const void *bytes unlink(auxPath); return false; } - - // If the file was renamed successfully and we wrote it as root we need to reset the owner & group as they were. - if (writingFileAsRoot) { - chown(cpath, owner, group); - } } return true; }