Skip to content

Commit

Permalink
Allow new_ rules to overwrited BUILD files in downloaded repos
Browse files Browse the repository at this point in the history
My previous change carefully checked that the file was a symlink before
removing it and added a test with local repositories... and it of course isn't
a symlink with downloaded repositories and crashes.

Fixes #1697.

--
MOS_MIGRATED_REVID=134536130
  • Loading branch information
kchodorow authored and katre committed Sep 30, 2016
1 parent dfbbc1c commit 4c73391
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.vfs.RootedPath;
import com.google.devtools.build.lib.vfs.Symlinks;
import com.google.devtools.build.skyframe.SkyFunction;
import com.google.devtools.build.skyframe.SkyFunction.Environment;
import com.google.devtools.build.skyframe.SkyFunctionException;
Expand Down Expand Up @@ -198,9 +199,10 @@ protected static RepositoryDirectoryValue writeBuildFile(
Path repositoryDirectory, String contents) throws RepositoryFunctionException {
Path buildFilePath = repositoryDirectory.getRelative("BUILD");
try {
// Make sure we're not overwriting an existing BUILD file.
if (buildFilePath.exists()) {
Preconditions.checkState(buildFilePath.isSymbolicLink());
// The repository could have an existing BUILD file that's either a regular file (for remote
// repositories) or a symlink (for local repositories). Either way, we want to remove it and
// write our own.
if (buildFilePath.exists(Symlinks.NOFOLLOW)) {
buildFilePath.delete();
}
FileSystemUtils.writeContentAsLatin1(buildFilePath, contents);
Expand Down
3 changes: 2 additions & 1 deletion src/test/shell/bazel/external_integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,8 @@ EOF
function test_changing_build_file() {
echo "abc" > w
echo "def" > w.new
tar czf x.tar.gz w w.new
echo "I'm a build file" > BUILD
tar czf x.tar.gz w w.new BUILD
local sha256=$(sha256sum x.tar.gz | cut -f 1 -d ' ')
serve_file x.tar.gz

Expand Down

0 comments on commit 4c73391

Please sign in to comment.