Skip to content

Commit

Permalink
[8.0.0] Fix permissions on directories while incrementally updating a…
Browse files Browse the repository at this point in the history
… symlink tree. (#24292)

Compare with EnsureDirReadAndWritePerms in build-runfiles.cc.

PiperOrigin-RevId: 695254434
Change-Id: If8694ad4fdd666739419ca02373a35a2cf36f4ac
  • Loading branch information
tjgq authored Nov 12, 2024
1 parent 2c9430d commit 0477f38
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,15 @@ void syncTreeRecursively(Path at) throws IOException {
} else if (!stat.isDirectory()) {
at.deleteTree();
at.createDirectoryAndParents();
} else {
// If the directory already exists, ensure it has appropriate permissions.
int perms = stat.getPermissions();
if (perms == -1) {
at.chmod(0755);
} else if ((perms & 0700) != 0700) {
at.chmod(stat.getPermissions() | 0700);
}
}
// TODO(ulfjack): provide the mode bits from FileStatus and use that to construct the correct
// chmod call here. Note that we do not have any tests for this right now. Something like
// this:
// if (!stat.isExecutable() || !stat.isReadable()) {
// at.chmod(stat.getMods() | 0700);
// }
for (Dirent dirent : at.readdir(Symlinks.NOFOLLOW)) {
String basename = dirent.getName();
Path next = at.getChild(basename);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public void createSymlinksDirectly(@TestParameter boolean replace) throws Except
treeFile.createDirectoryAndParents();
treeSymlink.createDirectoryAndParents();
treeMissing.createDirectoryAndParents();
treeWorkspace.chmod(000);
}

helper.createSymlinksDirectly(symlinkMap);
Expand Down

0 comments on commit 0477f38

Please sign in to comment.