From 1f213a5b07bb6c1aeff80c3bbe74b8230dd506f6 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 5 Apr 2018 15:59:56 -0300 Subject: Read namespace on disk search as well --- src/luarocks/search.lua | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua index 54ddd517..a86db890 100644 --- a/src/luarocks/search.lua +++ b/src/luarocks/search.lua @@ -47,6 +47,25 @@ local function store_if_match(result_tree, result, query) end end +--- Get the namespace of a locally-installed rock, if any. +-- @param name string: The rock name, without a namespace. +-- @param version string: The rock version. +-- @param tree string: The local tree to use. +-- @return string?: The namespace if it exists, or nil. +local function read_namespace(name, version, tree) + assert(type(name) == "string") + assert(type(version) == "string") + assert(type(tree) == "string") + + local namespace + local fd = io.open(path.rock_namespace_file(name, version, tree), "r") + if fd then + namespace = fd:read("*a") + fd:close() + end + return namespace +end + --- Perform search on a local repository. -- @param repo string: The pathname of the local repository. -- @param query table: a query object. @@ -77,8 +96,7 @@ function search.disk_search(repo, query, result_tree) elseif fs.is_dir(pathname) then for version in fs.dir(pathname) do if version:match("-%d+$") then - local namespace = nil - -- FIXME read rock_namespace file + local namespace = read_namespace(name, version, repo) local result = results.new(name, version, repo, "installed", namespace) store_if_match(result_tree, result, query) end @@ -88,16 +106,6 @@ function search.disk_search(repo, query, result_tree) return result_tree end -local function read_namespace(name, version, tree) - local namespace - local fd = io.open(path.rock_namespace_file(name, version, tree), "r") - if fd then - namespace = fd:read("*a") - fd:close() - end - return namespace -end - --- Perform search on a rocks server or tree. -- @param result_tree table: The result tree, where keys are package names and -- values are tables matching version strings to arrays of -- cgit v1.2.3-55-g6feb