Skip to content

Commit

Permalink
repository_context.read: drop restriction to current repository
Browse files Browse the repository at this point in the history
Currently, the read function of the repository context is restricted
to the external repository it is supposed to construct. However,
external repositories are routinely used for configure-like tasks
that inspect a lot of files all over the system and then write a
consolidated descripton of the system to the generated repository. In
fact, even for simple tasks like authentication for http_downloads,
we had to work around that restriction by symlinking the needed
file into the current repository before reading it (followed by
removing the symlink). So simply drop that restriction.

RELNOTES: repository_ctx.read is no longer restricted to files
    in the repository contructed.

Change-Id: I9d5003e00ae2acf9312b7fd65af7a40434933436
PiperOrigin-RevId: 258181706
  • Loading branch information
aehlig authored and copybara-github committed Jul 15, 2019
1 parent c60675a commit f380735
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ public String readFile(Object path, Location location)
WorkspaceRuleEvent.newReadEvent(p.toString(), rule.getLabel().toString(), location);
env.getListener().post(w);
try {
checkInOutputDirectory("read", p);
return FileSystemUtils.readContent(p.getPath(), StandardCharsets.ISO_8859_1);
} catch (IOException e) {
throw new RepositoryFunctionException(e, Transience.TRANSIENT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,34 +251,6 @@ public void testRead() throws Exception {

String content = context.readFile(context.path("foo/bar"), null);
assertThat(content).isEqualTo("foobar");

try {
context.readFile(context.path("/absolute"), null);
fail("Expected error on reading path outside of the repository directory");
} catch (RepositoryFunctionException ex) {
assertThat(ex)
.hasCauseThat()
.hasMessageThat()
.isEqualTo("Cannot read outside of the repository directory for path /absolute");
}
try {
context.readFile(context.path("../somepath"), null);
fail("Expected error on reading path outside of the repository directory");
} catch (RepositoryFunctionException ex) {
assertThat(ex)
.hasCauseThat()
.hasMessageThat()
.isEqualTo("Cannot read outside of the repository directory for path /somepath");
}
try {
context.readFile(context.path("foo/../../somepath"), null);
fail("Expected error on reading path outside of the repository directory");
} catch (RepositoryFunctionException ex) {
assertThat(ex)
.hasCauseThat()
.hasMessageThat()
.isEqualTo("Cannot read outside of the repository directory for path /somepath");
}
}

@Test
Expand Down

0 comments on commit f380735

Please sign in to comment.