Skip to content

Commit

Permalink
Only chmod files in ActionMetadataHandler if necessary
Browse files Browse the repository at this point in the history
This ensures that the ctime of the files doesn't change if no permission
change is necessary, thereby improving the hit rate of the digest cache.
  • Loading branch information
fmeum committed Apr 6, 2023
1 parent 0ba0fad commit 1affa3e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,8 @@ private static FileArtifactValue fileArtifactValueFromStat(
}

private void setPathPermissionsIfFile(Path path) throws IOException {
if (path.isFile(Symlinks.NOFOLLOW)) {
FileStatus stat = path.stat(Symlinks.NOFOLLOW);
if (stat.isFile() && stat.getPermissions() != outputPermissions.getPermissionsMode()) {
setPathPermissions(path);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ public long getNodeId() {
return status.getInodeNumber();
}

int getPermissions() {
@Override
public int getPermissions() {
return status.getPermissions();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,12 @@ public interface FileStatus {
* ought to cause the node ID of b to change, but appending / modifying b should not.
*/
long getNodeId() throws IOException;

/**
* Returns the file's permissions in POSIX format (e.g. 0755) if possible without performing
* additional IO, otherwise (or if unsupported by the file system) returns -1.
*/
default int getPermissions() {
return -1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ public long getNodeId() {
// TODO(bazel-team): Consider making use of attributes.fileKey().
return -1;
}

@Override
public int getPermissions() {
// Files on Windows are implicitly readable and executable.
return 0555 | (attributes.isReadOnly() ? 0 : 0200);
}
};

return status;
Expand Down

0 comments on commit 1affa3e

Please sign in to comment.