aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeoff Leyland <geoff.leyland@incremental.co.nz>2015-12-23 09:43:43 +1300
committerGeoff Leyland <geoff.leyland@incremental.co.nz>2015-12-23 09:43:43 +1300
commite45f2a6bb460d0690722e862152a274ada15d300 (patch)
tree9af50dadbc2bba95f95f9b85d3b949adacd68d8e /src
parent9fe6923d37a9e3b35428cfa631da60fdd6a89f95 (diff)
downloadluarocks-e45f2a6bb460d0690722e862152a274ada15d300.tar.gz
luarocks-e45f2a6bb460d0690722e862152a274ada15d300.tar.bz2
luarocks-e45f2a6bb460d0690722e862152a274ada15d300.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/fetch.lua27
1 files changed, 26 insertions, 1 deletions
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)
355 if not ok then return nil, err end 355 if not ok then return nil, err end
356 fs.unpack_archive(rockspec.source.file) 356 fs.unpack_archive(rockspec.source.file)
357 if not fs.exists(rockspec.source.dir) then 357 if not fs.exists(rockspec.source.dir) then
358 return nil, "Directory "..rockspec.source.dir.." not found inside archive "..rockspec.source.file, "source.dir", source_file, store_dir 358
359 -- if rockspec.source.dir can't be found, see if we only have one
360 -- directory in store_dir. If that's the case, assume it's what
361 -- we're looking for.
362 -- Ideally, we'd only do this if rockspec.source.dir was not
363 -- defined in the rockspec, but load_local_repository already
364 -- set it to an inferred value if it wasn't set there, so we
365 -- can't tell its status in the rockspec.
366 -- In any case, we only do this with rockspecs newer than 3.0.
367 local dir_count, found_dir = 0
368
369 if deps.format_is_at_least(rockspec, "3.0") then
370 local files = fs.list_dir()
371 for _, f in ipairs(files) do
372 if fs.is_dir(f) then
373 dir_count = dir_count + 1
374 found_dir = f
375 end
376 end
377 end
378
379 if dir_count == 1 then
380 rockspec.source.dir = found_dir
381 else
382 return nil, "Directory "..rockspec.source.dir.." not found inside archive "..rockspec.source.file, "source.dir", source_file, store_dir
383 end
359 end 384 end
360 fs.pop_dir() 385 fs.pop_dir()
361 end 386 end