Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Apr 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Sparkle/SUFileManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
23 changes: 19 additions & 4 deletions Sparkle/SUFileManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -434,15 +434,30 @@ - (BOOL)changeOwnerAndGroupOfItemAtRootURL:(NSURL *)targetURL toMatchURL:(NSURL
// 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;
}
}
Expand Down