aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormpeterv <mpeterval@gmail.com>2016-03-20 12:57:43 +0300
committermpeterv <mpeterval@gmail.com>2016-03-20 13:14:41 +0300
commitb29a5d1ac614b02d0c8b7b0a4a7413a8d77007c6 (patch)
tree0e5033b074b2649b43040854dc0c1c6482be3b52
parent0e0d4ea53d4791e051d7dd82103da5805ba22558 (diff)
downloadluarocks-b29a5d1ac614b02d0c8b7b0a4a7413a8d77007c6.tar.gz
luarocks-b29a5d1ac614b02d0c8b7b0a4a7413a8d77007c6.tar.bz2
luarocks-b29a5d1ac614b02d0c8b7b0a4a7413a8d77007c6.zip
Refactor download.download
search.find_suitable_rock now can't return a table.
-rw-r--r--src/luarocks/download.lua31
1 files changed, 13 insertions, 18 deletions
diff --git a/src/luarocks/download.lua b/src/luarocks/download.lua
index 74ed40e9..d241fca8 100644
--- a/src/luarocks/download.lua
+++ b/src/luarocks/download.lua
@@ -37,26 +37,21 @@ local function get_file(filename)
37end 37end
38 38
39function download.download(arch, name, version, all) 39function download.download(arch, name, version, all)
40 local results, err
41 local query = search.make_query(name, version) 40 local query = search.make_query(name, version)
42 if arch then query.arch = arch end 41 if arch then query.arch = arch end
42
43 if all then 43 if all then
44 if name == "" then query.exact_name = false end 44 if name == "" then query.exact_name = false end
45 results = search.search_repos(query) 45 local results = search.search_repos(query)
46 else 46
47 results, err = search.find_suitable_rock(query) 47 if next(results) then
48 end
49 if type(results) == "string" then
50 return get_file(results)
51 elseif type(results) == "table" and next(results) then
52 if all then
53 local all_ok = true 48 local all_ok = true
54 local any_err = "" 49 local any_err = ""
55 for name, result in pairs(results) do 50 for name, result in pairs(results) do
56 for version, versions in pairs(result) do 51 for version, items in pairs(result) do
57 for _,items in pairs(versions) do 52 for _, item in ipairs(items) do
58 local filename = path.make_url(items.repo, name, version, items.arch) 53 local url = path.make_url(item.repo, name, version, item.arch)
59 local ok, err = get_file(filename) 54 local ok, err = get_file(url)
60 if not ok then 55 if not ok then
61 all_ok = false 56 all_ok = false
62 any_err = any_err .. "\n" .. err 57 any_err = any_err .. "\n" .. err
@@ -65,11 +60,11 @@ function download.download(arch, name, version, all)
65 end 60 end
66 end 61 end
67 return all_ok, any_err 62 return all_ok, any_err
68 else 63 end
69 util.printerr("Multiple search results were returned.") 64 else
70 util.title("Search results:") 65 local url = search.find_suitable_rock(query)
71 search.print_results(results) 66 if url then
72 return nil, "Please narrow your query or use --all." 67 return get_file(url)
73 end 68 end
74 end 69 end
75 return nil, "Could not find a result named "..name..(version and " "..version or "").."." 70 return nil, "Could not find a result named "..name..(version and " "..version or "").."."