Skip to content

Commit

Permalink
create new AclEntry with correct principal if ownerEntry is not found…
Browse files Browse the repository at this point in the history
… in ACL list
  • Loading branch information
thurka committed Jan 9, 2025
1 parent b9ac871 commit 8d27edc
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import static java.nio.file.attribute.AclEntryPermission.WRITE_ATTRIBUTES;
import static java.nio.file.attribute.AclEntryPermission.WRITE_DATA;
import static java.nio.file.attribute.AclEntryPermission.WRITE_NAMED_ATTRS;
import java.nio.file.attribute.AclEntryType;
import java.nio.file.attribute.AclFileAttributeView;
import java.nio.file.attribute.DosFileAttributeView;
import java.nio.file.attribute.FileAttribute;
Expand Down Expand Up @@ -163,12 +164,16 @@ private void writeToFile(WriterConsumer c, Path filePath) throws IOException {
private void setFileOwnerAcl(Path filePath, Set<AclEntryPermission> permissions) throws IOException {
AclFileAttributeView acl = Files.getFileAttributeView(filePath, AclFileAttributeView.class);
AclEntry ownerEntry = findFileOwner(acl);
AclEntry.Builder aclBuilder;

if (ownerEntry == null) {
throw new IOException("Owner missing, file:" + filePath.toString()); // NOI18N
}
LOG.info("Owner missing, file:" + filePath.toString()); // NOI18N
aclBuilder = AclEntry.newBuilder().setPrincipal(acl.getOwner()).setType(AclEntryType.ALLOW);
} else {
aclBuilder = AclEntry.newBuilder(ownerEntry);
}

AclEntry ownerAcl = AclEntry.newBuilder(ownerEntry).setPermissions(permissions).build();
AclEntry ownerAcl = aclBuilder.setPermissions(permissions).build();
acl.setAcl(Collections.singletonList(ownerAcl));
}

Expand Down

0 comments on commit 8d27edc

Please sign in to comment.