Skip to content

Commit

Permalink
Don't crash on an absolute --client_cwd value that is not in the work…
Browse files Browse the repository at this point in the history
…space.

PiperOrigin-RevId: 313225953
  • Loading branch information
janakdr authored and copybara-github committed May 26, 2020
1 parent 5fa85c8 commit 1557ac8
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,22 +248,36 @@ private Path computeWorkingDirectory(CommonCommandOptions commandOptions)
Path workspace = getWorkspace();
Path workingDirectory;
if (inWorkspace()) {
if (commandOptions.clientCwd.containsUplevelReferences()) {
PathFragment clientCwd = commandOptions.clientCwd;
if (clientCwd.containsUplevelReferences()) {
throw new AbruptExitException(
DetailedExitCode.of(
ExitCode.COMMAND_LINE_ERROR,
FailureDetail.newBuilder()
.setMessage("Client cwd contains uplevel references")
.setMessage("Client cwd '" + clientCwd + "' contains uplevel references")
.setClientEnvironment(
FailureDetails.ClientEnvironment.newBuilder()
.setCode(FailureDetails.ClientEnvironment.Code.CLIENT_CWD_MALFORMED)
.build())
.build()));
}
workingDirectory = workspace.getRelative(commandOptions.clientCwd);
if (clientCwd.isAbsolute() && !clientCwd.startsWith(workspace.asFragment())) {
throw new AbruptExitException(
DetailedExitCode.of(
ExitCode.COMMAND_LINE_ERROR,
FailureDetail.newBuilder()
.setMessage(
String.format(
"Client cwd '%s' is not inside workspace '%s'", clientCwd, workspace))
.setClientEnvironment(
FailureDetails.ClientEnvironment.newBuilder()
.setCode(FailureDetails.ClientEnvironment.Code.CLIENT_CWD_MALFORMED)
.build())
.build()));
}
workingDirectory = workspace.getRelative(clientCwd);
} else {
workspace = FileSystemUtils.getWorkingDirectory(getRuntime().getFileSystem());
workingDirectory = workspace;
workingDirectory = FileSystemUtils.getWorkingDirectory(getRuntime().getFileSystem());
}
return workingDirectory;
}
Expand Down

0 comments on commit 1557ac8

Please sign in to comment.