Skip to content

Commit

Permalink
Check execute permission on last directory
Browse files Browse the repository at this point in the history
Fixes #159
  • Loading branch information
marschall committed Sep 22, 2024
1 parent 95ea9b7 commit 9016236
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ public GetEntryResult value(MemoryDirectory directory) throws IOException {
MemoryFile file = this.createEntryOnAccess(path, newAttributes, directory, elementPath, creationContext);
return new GetEntryResult(file);
} else {
directory.checkAccess(AccessMode.EXECUTE);
MemoryEntry storedEntry = directory.getEntry(key);
if (storedEntry == null) {
boolean isCreate = options.contains(CREATE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,4 +352,18 @@ void issue138() throws IOException {
}
}

@Test
void issue159() throws IOException {
FileSystem fileSystem = this.extension.getFileSystem();
Path path = fileSystem.getPath("/", "sub1", "sub2", "test.txt");
Path parent = path.getParent();
FileUtility.createAndSetContents(path, "Hello World");
Set<PosixFilePermission> previousPermissions = Files.getPosixFilePermissions(parent);
EnumSet<PosixFilePermission> noExecute = EnumSet.copyOf(previousPermissions);
noExecute.removeAll(EnumSet.of(PosixFilePermission.GROUP_EXECUTE, PosixFilePermission.OTHERS_EXECUTE, PosixFilePermission.OWNER_EXECUTE));
Files.setPosixFilePermissions(parent, noExecute); // removes execute permission
assertEquals(noExecute, Files.getPosixFilePermissions(parent));
assertThrows(AccessDeniedException.class, () -> Files.readAllBytes(path));
}

}

0 comments on commit 9016236

Please sign in to comment.