Don't bring up authorization just because group ID doesn't match

This commit is contained in:
Zorg committed 2021-04-17 13:47:00 -07:00
1 parent 2d0b9ae356
commit af9935540a
2 files changed
+20 -4

No files matched your search

+1
View File
@@ -103,6 +103,7 @@ NS_ASSUME_NONNULL_BEGIN
* If the owner and group IDs match on the root items of targetURL and matchURL, this method stops and assumes that nothing needs to be done.
* Otherwise this method recursively changes the IDs if the target is a directory. If an item in the directory is encountered that is unable to be changed,
* then this method stops and returns NO.
* While this method will try to change the group ID, being unable to change the group ID does not result in a failure if the owner ID can be changed or matched.
*
* This is not an atomic operation.
*/
+19 -4
View File
@@ -434,15 +434,30 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) {
// Speeds up the common case
return YES;
}
if (![self _changeOwnerAndGroupOfItemAtURL:targetURL ownerID:ownerID groupID:groupID error:error]) {
return NO;
// If we can't change both the new owner & group, try to only change the owner
// If this works, this is sufficient enough for performing the update
NSNumber *groupIDToUse;
if (![self _changeOwnerAndGroupOfItemAtURL:targetURL ownerID:ownerID groupID:groupID error:NULL]) {
if ((targetOwnerID != nil && [ownerID isEqualToNumber:targetOwnerID])) {
// Assume they're the same even if we don't check every file recursively
// Speeds up the common case like above
return YES;
}
if (![self _changeOwnerAndGroupOfItemAtURL:targetURL ownerID:ownerID groupID:targetGroupID error:error]) {
return NO;
}
groupIDToUse = targetGroupID;
} else {
groupIDToUse = groupID;
}
if (isTargetADirectory) {
NSDirectoryEnumerator *directoryEnumerator = [_fileManager enumeratorAtURL:targetURL includingPropertiesForKeys:nil options:(NSDirectoryEnumerationOptions)0 errorHandler:nil];
for (NSURL *url in directoryEnumerator) {
if (![self _changeOwnerAndGroupOfItemAtURL:url ownerID:ownerID groupID:groupID error:error]) {
if (![self _changeOwnerAndGroupOfItemAtURL:url ownerID:ownerID groupID:groupIDToUse error:error]) {
return NO;
}
}