diff options
author | mpeterv <mpeterval@gmail.com> | 2016-03-19 13:54:10 +0300 |
---|---|---|
committer | mpeterv <mpeterval@gmail.com> | 2016-03-20 12:26:04 +0300 |
commit | 0e0d4ea53d4791e051d7dd82103da5805ba22558 (patch) | |
tree | 5850dec072a2243b30c1bc28987a0204dca3c473 /src | |
parent | f81fd2316d62e2ef64a6b46ba6fb088ea6d5f992 (diff) | |
download | luarocks-0e0d4ea53d4791e051d7dd82103da5805ba22558.tar.gz luarocks-0e0d4ea53d4791e051d7dd82103da5805ba22558.tar.bz2 luarocks-0e0d4ea53d4791e051d7dd82103da5805ba22558.zip |
Don't handle multiple rock queries in find_suitable_rock
In practice search.find_suitable_rock is always
called with a precise query (no fuzzy name matching),
and not all callers handle table as return value correctly.
Diffstat (limited to 'src')
-rw-r--r-- | src/luarocks/deps.lua | 8 | ||||
-rw-r--r-- | src/luarocks/install.lua | 16 | ||||
-rw-r--r-- | src/luarocks/search.lua | 37 |
3 files changed, 25 insertions, 36 deletions
diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index a2215351..278b6356 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua | |||
@@ -484,13 +484,13 @@ function deps.fulfill_dependencies(rockspec, deps_mode) | |||
484 | for _, dep in pairs(missing) do | 484 | for _, dep in pairs(missing) do |
485 | -- Double-check in case dependency was filled during recursion. | 485 | -- Double-check in case dependency was filled during recursion. |
486 | if not match_dep(dep, nil, deps_mode) then | 486 | if not match_dep(dep, nil, deps_mode) then |
487 | local rock = search.find_suitable_rock(dep) | 487 | local url, err = search.find_suitable_rock(dep) |
488 | if not rock then | 488 | if not url then |
489 | return nil, "Could not satisfy dependency: "..deps.show_dep(dep) | 489 | return nil, "Could not satisfy dependency: "..deps.show_dep(dep) |
490 | end | 490 | end |
491 | local ok, err, errcode = install.run(rock, deps.deps_mode_to_flag(deps_mode)) | 491 | local ok, err, errcode = install.run(url, deps.deps_mode_to_flag(deps_mode)) |
492 | if not ok then | 492 | if not ok then |
493 | return nil, "Failed installing dependency: "..rock.." - "..err, errcode | 493 | return nil, "Failed installing dependency: "..url.." - "..err, errcode |
494 | end | 494 | end |
495 | end | 495 | end |
496 | end | 496 | end |
diff --git a/src/luarocks/install.lua b/src/luarocks/install.lua index 6d457fc2..c938aa9f 100644 --- a/src/luarocks/install.lua +++ b/src/luarocks/install.lua | |||
@@ -186,20 +186,12 @@ function install.run(...) | |||
186 | return name, version | 186 | return name, version |
187 | else | 187 | else |
188 | local search = require("luarocks.search") | 188 | local search = require("luarocks.search") |
189 | local results, err = search.find_suitable_rock(search.make_query(name:lower(), version)) | 189 | local url, err = search.find_suitable_rock(search.make_query(name:lower(), version)) |
190 | if err then | 190 | if not url then |
191 | return nil, err | 191 | return nil, err |
192 | elseif type(results) == "string" then | ||
193 | local url = results | ||
194 | util.printout("Installing "..url.."...") | ||
195 | return install.run(url, util.forward_flags(flags)) | ||
196 | else | ||
197 | util.printout() | ||
198 | util.printerr("Could not determine which rock to install.") | ||
199 | util.title("Search results:") | ||
200 | search.print_results(results) | ||
201 | return nil, (next(results) and "Please narrow your query." or "No results found.") | ||
202 | end | 192 | end |
193 | util.printout("Installing "..url.."...") | ||
194 | return install.run(url, util.forward_flags(flags)) | ||
203 | end | 195 | end |
204 | end | 196 | end |
205 | 197 | ||
diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua index 32af1f9e..5e6cf50e 100644 --- a/src/luarocks/search.lua +++ b/src/luarocks/search.lua | |||
@@ -278,28 +278,26 @@ local function pick_latest_version(name, versions) | |||
278 | return nil | 278 | return nil |
279 | end | 279 | end |
280 | 280 | ||
281 | --- Attempt to get a single URL for a given search. | 281 | --- Attempt to get a single URL for a given search for a rock. |
282 | -- @param query table: A dependency query. | 282 | -- @param query table: A dependency query matching a single rock. |
283 | -- @return string or table or (nil, string): URL for matching rock if | 283 | -- @return string or (nil, string): URL for latest matching version |
284 | -- a single one was found, a table of candidates if it could not narrow to | 284 | -- of the rock if it was found, or nil followed by an error message. |
285 | -- a single result, or nil followed by an error message. | ||
286 | function search.find_suitable_rock(query) | 285 | function search.find_suitable_rock(query) |
287 | assert(type(query) == "table") | 286 | assert(type(query) == "table") |
288 | 287 | ||
289 | local results = search.search_repos(query) | 288 | local results = search.search_repos(query) |
290 | local first = next(results) | 289 | local first_rock = next(results) |
291 | if not first then | 290 | if not first_rock then |
292 | return nil, "No results matching query were found." | 291 | return nil, "No results matching query were found." |
293 | elseif not next(results, first) then | 292 | elseif next(results, first_rock) then |
294 | if cfg.rocks_provided[query.name] ~= nil then | 293 | -- Shouldn't happen as query must match only one package. |
295 | -- do not install versions that listed in cfg.rocks_provided | 294 | return nil, "Several rocks matched query." |
296 | return nil, "Rock "..query.name.. | 295 | elseif cfg.rocks_provided[query.name] ~= nil then |
297 | " "..cfg.rocks_provided[query.name].. | 296 | -- Do not install versions listed in cfg.rocks_provided. |
298 | " was found but it is provided by VM or 'rocks_provided' in the config file." | 297 | return nil, "Rock "..query.name.." "..cfg.rocks_provided[query.name].. |
299 | end | 298 | " was found but it is provided by VM or 'rocks_provided' in the config file." |
300 | return pick_latest_version(query.name, results[first]) | ||
301 | else | 299 | else |
302 | return results | 300 | return pick_latest_version(query.name, results[first_rock]) |
303 | end | 301 | end |
304 | end | 302 | end |
305 | 303 | ||
@@ -369,12 +367,11 @@ function search.act_on_src_or_rockspec(action, name, version, ...) | |||
369 | 367 | ||
370 | local query = search.make_query(name, version) | 368 | local query = search.make_query(name, version) |
371 | query.arch = "src|rockspec" | 369 | query.arch = "src|rockspec" |
372 | local results, err = search.find_suitable_rock(query) | 370 | local url, err = search.find_suitable_rock(query) |
373 | if type(results) == "string" then | 371 | if not url then |
374 | return action(results, ...) | ||
375 | else | ||
376 | return nil, "Could not find a result named "..name..(version and " "..version or "").."." | 372 | return nil, "Could not find a result named "..name..(version and " "..version or "").."." |
377 | end | 373 | end |
374 | return action(url, ...) | ||
378 | end | 375 | end |
379 | 376 | ||
380 | --- Driver function for "search" command. | 377 | --- Driver function for "search" command. |