Skip to content

Commit

Permalink
Merge pull request #8133 from thurka/thurka/GCN-5326
Browse files Browse the repository at this point in the history
create new AclEntry if ownerEntry is not found
  • Loading branch information
thurka authored Jan 9, 2025
2 parents 7fb80d2 + 8d27edc commit 56b8332
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 @@ -164,12 +165,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 56b8332

Please sign in to comment.