Skip to content

Commit

Permalink
add AclEntryType.OTHER if absent while preserving acls during distcp
Browse files Browse the repository at this point in the history
  • Loading branch information
Meeth Gala committed Aug 30, 2023
1 parent 0ab094a commit e898825
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.permission.AclEntry;
import org.apache.hadoop.fs.permission.AclEntryScope;
import org.apache.hadoop.fs.permission.AclEntryType;
import org.apache.hadoop.fs.permission.AclStatus;
import org.apache.hadoop.fs.permission.FsAction;
import org.apache.hadoop.fs.permission.FsPermission;

import com.google.common.base.Optional;
Expand Down Expand Up @@ -441,7 +444,33 @@ public static Map<String, OwnerAndPermission> resolveReplicatedAncestorOwnerAndP

private static List<AclEntry> getAclEntries(FileSystem srcFs, Path path) throws IOException {
AclStatus aclStatus = srcFs.getAclStatus(path);
return aclStatus.getEntries();
return addOthersEntryTypeToAclEntriesIfMissing(aclStatus.getEntries());
}
/*
* When we get AclEntry from org.apache.hadoop.fs.permission.AclStatus, it's missing AclEntryType.OTHER.
* This causes AclTransformation validation to fail on the list of AclEntries. As a result, adding this helper
* method to provide DEFAULT scope in cases where AclEntryType.OTHER is absent
*/
private static List<AclEntry> addOthersEntryTypeToAclEntriesIfMissing(List<AclEntry> aclEntries) {
// Check if "others" entry is missing
boolean othersAclEntryTypeMissing = true;

for (AclEntry aclEntry : aclEntries) {
if (aclEntry.getType() == AclEntryType.OTHER) {
othersAclEntryTypeMissing = false;
break;
}
}
// If "others" entry is missing, add it
if (othersAclEntryTypeMissing) {
AclEntry othersEntry = new AclEntry.Builder().setType(AclEntryType.OTHER).setScope(AclEntryScope.DEFAULT)
.setPermission(FsAction.READ_EXECUTE).build();

// Modify the ACL entries to include the new "others" entry
aclEntries.add(othersEntry);
}
return aclEntries;

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,8 @@ public static void safeSetPathPermission(FileSystem fs, FileStatus file, OwnerAn
if (targetOwnerAndPermission.getFsPermission() != null) {
fs.setPermission(path, targetOwnerAndPermission.getFsPermission());
}
if (!ownerAndPermission.getAclEntries().isEmpty()) {
fs.setAcl(path, ownerAndPermission.getAclEntries());
if (!targetOwnerAndPermission.getAclEntries().isEmpty()) {
fs.setAcl(path, targetOwnerAndPermission.getAclEntries());
}
} catch (IOException ioe) {
log.warn("Failed to set permission for directory " + path, ioe);
Expand Down

0 comments on commit e898825

Please sign in to comment.