Skip to content

Commit

Permalink
[7.1.0] Avoid exception-based control flow in RemoteActionFileSystem#…
Browse files Browse the repository at this point in the history
…stat. (#21236)

When statting a file in the local filesystem, we first call
InMemoryFileSystem#stat, which unnecessarily allocates and throws a
FileNotFoundException. Instead, call InMemoryFileSystem#statIfFound,
which doesn't.

PiperOrigin-RevId: 604253151
Change-Id: Iabb9573f710e657a9ea893f1f7577a6b4bb147d2
  • Loading branch information
tjgq authored Feb 7, 2024
1 parent 3a006ec commit ffa8004
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -605,14 +605,16 @@ private FileStatus statUnchecked(
}
}

try {
return remoteOutputTree.stat(path, /* followSymlinks= */ false);
} catch (FileNotFoundException e) {
if (statSources == StatSources.ALL) {
return localFs.getPath(path).stat(Symlinks.NOFOLLOW);
}
throw e;
FileStatus stat = remoteOutputTree.statIfFound(path, /* followSymlinks= */ false);
if (stat != null) {
return stat;
}

if (statSources == StatSources.ALL) {
return localFs.getPath(path).stat(Symlinks.NOFOLLOW);
}

throw new FileNotFoundException(path.getPathString() + " (No such file or directory)");
}

private static FileStatusWithMetadata statFromMetadata(FileArtifactValue m) {
Expand Down

0 comments on commit ffa8004

Please sign in to comment.