Skip to content

Commit

Permalink
Add support for .tbz file extension in repository_ctx.download_and_ex…
Browse files Browse the repository at this point in the history
…tract

The `download_and_extract` function supported `.tar.bz2` files, but did not recognize `.tbz` as a valid file extension for those. This commit simply adds support for this, in the code, in the test and in the doc.

Fixes #17824

Closes #17825.

PiperOrigin-RevId: 520049316
Change-Id: Id4a1716304734f58a06cf5dc8d481642f631f5e1
  • Loading branch information
benjamin-sb authored and Copybara-Service committed Mar 28, 2023
1 parent 8ab9c6e commit 6e01b25
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Expand Up @@ -102,15 +102,15 @@ static Decompressor getDecompressor(Path archivePath) throws RepositoryFunctionE
return TarXzFunction.INSTANCE;
} else if (baseName.endsWith(".tar.zst") || baseName.endsWith(".tzst")) {
return TarZstFunction.INSTANCE;
} else if (baseName.endsWith(".tar.bz2")) {
} else if (baseName.endsWith(".tar.bz2") || baseName.endsWith(".tbz")) {
return TarBz2Function.INSTANCE;
} else if (baseName.endsWith(".ar") || baseName.endsWith(".deb")) {
return ArFunction.INSTANCE;
} else {
throw new RepositoryFunctionException(
Starlark.errorf(
"Expected a file with a .zip, .jar, .war, .aar, .tar, .tar.gz, .tgz, .tar.xz, .txz,"
+ " .tar.zst, .tzst, .tar.bz2, .ar or .deb suffix (got %s)",
+ " .tar.zst, .tzst, .tar.bz2, .tbz, .ar or .deb suffix (got %s)",
archivePath),
Transience.PERSISTENT);
}
Expand Down
Expand Up @@ -564,13 +564,11 @@ public StructImpl download(
defaultValue = "''",
named = true,
doc =
"the archive type of the downloaded file."
+ " By default, the archive type is determined from the file extension of"
+ " the URL."
+ " If the file has no extension, you can explicitly specify either \"zip\","
+ " \"jar\", \"war\", \"aar\", \"tar\", \"tar.gz\", \"tgz\", \"tar.xz\","
+ " \"txz\", \".tar.zst\", \".tzst\", \"tar.bz2\", \".ar\", or \".deb\""
+ " here."),
"the archive type of the downloaded file. By default, the archive type is"
+ " determined from the file extension of the URL. If the file has no"
+ " extension, you can explicitly specify either \"zip\", \"jar\", \"war\","
+ " \"aar\", \"tar\", \"tar.gz\", \"tgz\", \"tar.xz\", \"txz\", \".tar.zst\","
+ " \".tzst\", \"tar.bz2\", \".tbz\", \".ar\", or \".deb\" here."),
@Param(
name = "stripPrefix",
defaultValue = "''",
Expand Down
Expand Up @@ -57,6 +57,8 @@ public void testKnownFileExtensionsDoNotThrow() throws Exception {
unused = DecompressorValue.getDecompressor(path);
path = fs.getPath("/foo/.external-repositories/some-repo/bar.baz.tar.bz2");
unused = DecompressorValue.getDecompressor(path);
path = fs.getPath("/foo/.external-repositories/some-repo/bar.baz.tbz");
unused = DecompressorValue.getDecompressor(path);
path = fs.getPath("/foo/.external-repositories/some-repo/bar.baz.ar");
unused = DecompressorValue.getDecompressor(path);
path = fs.getPath("/foo/.external-repositories/some-repo/bar.baz.deb");
Expand Down

0 comments on commit 6e01b25

Please sign in to comment.