From 6ef95c8f0a1dfffdefa322b0249fe7f74acec1fa Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Sat, 12 Nov 2016 00:35:46 +0300 Subject: Fix module paths `luarocks show` displays for "asset" files Instead of using path.which that produced incorrect results for files with no .lua/.so/.dll extension, reimplement similar functionality in luarocks.repos (with support for commands as well) and use that. Ref #424. --- src/luarocks/repos.lua | 27 +++++++++++++++++++++++++-- src/luarocks/show.lua | 5 +++-- 2 files changed, 28 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/luarocks/repos.lua b/src/luarocks/repos.lua index 5d5eac70..abc62b0d 100644 --- a/src/luarocks/repos.lua +++ b/src/luarocks/repos.lua @@ -226,8 +226,9 @@ end -- item from the newest version of lexicographically smallest package -- is deployed using non-versioned name and others use versioned names. -local function get_deploy_paths(name, version, deploy_type, file_path) - local deploy_dir = cfg["deploy_" .. deploy_type .. "_dir"] +local function get_deploy_paths(name, version, deploy_type, file_path, repo) + repo = repo or cfg.root_dir + local deploy_dir = path["deploy_" .. deploy_type .. "_dir"](repo) local non_versioned = dir.path(deploy_dir, file_path) local versioned = path.versioned_name(non_versioned, deploy_dir, name, version) return non_versioned, versioned @@ -419,4 +420,26 @@ function repos.delete_version(name, version, deps_mode, quick) return manif.remove_from_manifest(name, version, nil, deps_mode) end +--- Find full path to a file providing a module or a command +-- in a package. +-- @param name string: name of package. +-- @param version string: exact package version in string format. +-- @param item_type string: "module" or "command". +-- @param item_name string: module or command name. +-- @param root string or nil: A local root dir for a rocks tree. If not given, the default is used. +-- @return string: absolute path to the file providing given module +-- or command. +function repos.which(name, version, item_type, item_name, repo) + local deploy_type, file_path = manif.get_providing_file(name, version, item_type, item_name, repo) + local non_versioned, versioned = get_deploy_paths(name, version, deploy_type, file_path, repo) + local cur_name, cur_version = manif.get_current_provider(item_type, item_name) + local deploy_path = (name == cur_name and version == cur_version) and non_versioned or versioned + + if deploy_type == "bin" and cfg.wrapper_suffix and cfg.wrapper_suffix ~= "" then + deploy_path = find_suffixed(deploy_path, cfg.wrapper_suffix) or deploy_path + end + + return deploy_path +end + return repos diff --git a/src/luarocks/show.lua b/src/luarocks/show.lua index 85c7edcb..8ec6394b 100644 --- a/src/luarocks/show.lua +++ b/src/luarocks/show.lua @@ -10,6 +10,7 @@ local path = require("luarocks.path") local deps = require("luarocks.deps") local fetch = require("luarocks.fetch") local manif = require("luarocks.manif") +local repos = require("luarocks.repos") util.add_run_function(show) show.help_summary = "Show information about an installed rock." @@ -118,8 +119,8 @@ function show.command(flags, name, version) if next(minfo.modules) then util.printout() util.printout("Modules:") - for mod, filename in util.sortedpairs(minfo.modules) do - util.printout("\t"..mod.." ("..path.which(mod, filename, name, version, repo, manifest)..")") + for mod in util.sortedpairs(minfo.modules) do + util.printout("\t"..mod.." ("..repos.which(name, version, "module", mod, repo)..")") end end local direct_deps = {} -- cgit v1.2.3-55-g6feb