From e45f2a6bb460d0690722e862152a274ada15d300 Mon Sep 17 00:00:00 2001 From: Geoff Leyland Date: Wed, 23 Dec 2015 09:43:43 +1300 Subject: If source.dir can't be found in a downloaded package in fetch.get_sources, but we find that the package only contains one directory, then use that directory. This helps for downloads from bitbucket, where the top-level directory of a zip download of master has a commit hash in its name. --- src/luarocks/fetch.lua | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua index e1cad11b..ef478658 100644 --- a/src/luarocks/fetch.lua +++ b/src/luarocks/fetch.lua @@ -355,7 +355,32 @@ function fetch.get_sources(rockspec, extract, dest_dir) if not ok then return nil, err end fs.unpack_archive(rockspec.source.file) if not fs.exists(rockspec.source.dir) then - return nil, "Directory "..rockspec.source.dir.." not found inside archive "..rockspec.source.file, "source.dir", source_file, store_dir + + -- if rockspec.source.dir can't be found, see if we only have one + -- directory in store_dir. If that's the case, assume it's what + -- we're looking for. + -- Ideally, we'd only do this if rockspec.source.dir was not + -- defined in the rockspec, but load_local_repository already + -- set it to an inferred value if it wasn't set there, so we + -- can't tell its status in the rockspec. + -- In any case, we only do this with rockspecs newer than 3.0. + local dir_count, found_dir = 0 + + if deps.format_is_at_least(rockspec, "3.0") then + local files = fs.list_dir() + for _, f in ipairs(files) do + if fs.is_dir(f) then + dir_count = dir_count + 1 + found_dir = f + end + end + end + + if dir_count == 1 then + rockspec.source.dir = found_dir + else + return nil, "Directory "..rockspec.source.dir.." not found inside archive "..rockspec.source.file, "source.dir", source_file, store_dir + end end fs.pop_dir() end -- cgit v1.2.3-55-g6feb