Skip to content

Commit

Permalink
Avoid exception-based control flow in RemoteActionFileSystem#stat.
Browse files Browse the repository at this point in the history
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 and copybara-github committed Feb 5, 2024
1 parent a133182 commit 9a86600
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -617,14 +617,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 9a86600

Please sign in to comment.