From c6e3556c0a883831dde10858b32ce21cacd1bd0e Mon Sep 17 00:00:00 2001 From: Ignacio BurgueƱo Date: Tue, 30 Jun 2015 12:33:36 -0300 Subject: Strip known extensions --- src/luarocks/fetch.lua | 7 ++++++- test/testing.lua | 12 ++++++++++++ test/testing.sh | 13 +++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua index 686aadcd..e92aeddf 100644 --- a/src/luarocks/fetch.lua +++ b/src/luarocks/fetch.lua @@ -170,8 +170,13 @@ function fetch.fetch_and_unpack_rock(rock_file, dest) end function fetch.url_to_base_dir(url) + -- for extensions like foo.tar.gz, "gz" is stripped first + local known_exts = {} + for _, ext in ipairs{"zip", "git", "tgz", "tar", "gz", "bz2"} do + known_exts[ext] = "" + end local base = dir.base_name(url) - return base:gsub("%.[^.]*$", ""):gsub("%.tar$", "") + return (base:gsub("%.([^.]*)$", known_exts):gsub("%.tar", "")) end --- Back-end function that actually loads the local rockspec. diff --git a/test/testing.lua b/test/testing.lua index 50911fd4..63dead2b 100644 --- a/test/testing.lua +++ b/test/testing.lua @@ -441,5 +441,17 @@ local tests = { return run "$luarocks install luarepl" and run "$luarocks doc luarepl" end, + + -- Tests for https://github.com/keplerproject/luarocks/issues/375 + test_fetch_base_dir = function() + local fetch = require "luarocks.fetch" + + return assert("v0.3" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2/archive/v0.3.zip")) + and assert("lua-compat-5.2" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.zip")) + and assert("lua-compat-5.2" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.tar.gz")) + and assert("lua-compat-5.2" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.tar.bz2")) + and assert("parser.moon" == fetch.url_to_base_dir("git://github.com/Cirru/parser.moon")) + and assert("v0.3" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2/archive/v0.3")) + end } diff --git a/test/testing.sh b/test/testing.sh index 133597ee..6219a38f 100755 --- a/test/testing.sh +++ b/test/testing.sh @@ -511,6 +511,19 @@ fail_config_user_config() { LUAROCKS_CONFIG="/missing_file.lua" $luarocks config test_config_rock_trees() { $luarocks config --rock-trees; } test_config_help() { $luarocks help config; } +# Tests for https://github.com/keplerproject/luarocks/issues/375 +test_fetch_base_dir() { $lua <