diff options
4 files changed, 11 insertions, 48 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/CompressedTarFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/CompressedTarFunction.java index 8b4a5f4022..daf6e66267 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/repository/CompressedTarFunction.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/CompressedTarFunction.java @@ -58,10 +58,7 @@ public abstract class CompressedTarFunction implements Decompressor { FileSystemUtils.createDirectoryAndParents(filename); } else { if (entry.isSymbolicLink() || entry.isLink()) { - // Strip the prefix from the link path if set - StripPrefixedPath linkPath = - StripPrefixedPath.maybeDeprefix(entry.getLinkName(), prefix); - PathFragment linkName = linkPath.getPathFragment(); + PathFragment linkName = new PathFragment(entry.getLinkName()); if (linkName.isAbsolute()) { linkName = linkName.relativeTo(PathFragment.ROOT_DIR); linkName = descriptor.repositoryPath().getRelative(linkName).asFragment(); diff --git a/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java b/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java index 73a9a5119f..c8d1f3c2c4 100644 --- a/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java +++ b/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java @@ -1010,19 +1010,19 @@ public class FileSystemUtils { */ public static void createHardLink(Path linkPath, Path originalPath) throws IOException { - // Directory - if (originalPath.isDirectory()) { - for (Path originalSubpath : originalPath.getDirectoryEntries()) { - Path linkSubpath = linkPath.getRelative(originalSubpath.relativeTo(originalPath)); - createHardLink(linkSubpath, originalSubpath); - } - // Other types of file - } else { + // Regular file + if (originalPath.isFile()) { Path parentDir = linkPath.getParentDirectory(); if (!parentDir.exists()) { FileSystemUtils.createDirectoryAndParents(parentDir); } originalPath.createHardLink(linkPath); + // Directory + } else if (originalPath.isDirectory()) { + for (Path originalSubpath : originalPath.getDirectoryEntries()) { + Path linkSubpath = linkPath.getRelative(originalSubpath.relativeTo(originalPath)); + createHardLink(linkSubpath, originalSubpath); + } } } } diff --git a/src/test/java/com/google/devtools/build/lib/rules/repository/CompressedTarFunctionTest.java b/src/test/java/com/google/devtools/build/lib/rules/repository/CompressedTarFunctionTest.java index 35305da87f..b638b21052 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/repository/CompressedTarFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/repository/CompressedTarFunctionTest.java @@ -54,8 +54,6 @@ public class CompressedTarFunctionTest { private static final String PATH_TO_TEST_ARCHIVE = "/com/google/devtools/build/lib/rules/repository/"; - private static final String ROOT_FOLDER_NAME = "root_folder"; - /* Tarball, created by * tar -czf <ARCHIVE_NAME> <REGULAR_FILE_NAME> <HARD_LINK_FILE_NAME> <SYMBOLIC_LINK_FILE_NAME> */ @@ -88,36 +86,12 @@ public class CompressedTarFunctionTest { } /** - * Test decompressing a tar.gz file with hard link file and symbolic link file inside without - * stripping a prefix - * - * @throws Exception - */ - @Test - public void testDecompressWithoutPrefix() throws Exception { - - Path outputDir = - new CompressedTarFunction() { - @Override - protected InputStream getDecompressorStream(DecompressorDescriptor descriptor) - throws IOException { - return new GZIPInputStream(new FileInputStream(descriptor.archivePath().getPathFile())); - } - }.decompress(descriptorBuilder.build()); - - assertOutputFiles(outputDir.getRelative(ROOT_FOLDER_NAME)); - } - - /** - * Test decompressing a tar.gz file with hard link file and symbolic link file inside and - * stripping a prefix + * Test decompressing a tar.gz file with hard link file and symbolic link file inside * * @throws Exception */ @Test - public void testDecompressWithPrefix() throws Exception { - - descriptorBuilder.setPrefix(ROOT_FOLDER_NAME); + public void testDecompress() throws Exception { Path outputDir = new CompressedTarFunction() { @@ -128,14 +102,6 @@ public class CompressedTarFunctionTest { } }.decompress(descriptorBuilder.build()); - assertOutputFiles(outputDir); - } - - /** - * Validate the content of the output directory - */ - private void assertOutputFiles(Path outputDir) throws Exception { - assertThat(outputDir.exists()).isTrue(); assertThat(outputDir.getRelative(REGULAR_FILE_NAME).exists()).isTrue(); assertThat(outputDir.getRelative(REGULAR_FILE_NAME).getFileSize()).isNotEqualTo(0); diff --git a/src/test/java/com/google/devtools/build/lib/rules/repository/test_decompress_archive.tar.gz b/src/test/java/com/google/devtools/build/lib/rules/repository/test_decompress_archive.tar.gz Binary files differindex b1bd70fafd..f951e97860 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/repository/test_decompress_archive.tar.gz +++ b/src/test/java/com/google/devtools/build/lib/rules/repository/test_decompress_archive.tar.gz |