From 74d0dbe353abce254b8c34ea67731900dedf5932 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 19 Apr 2010 19:15:00 -0300 Subject: Allow non-superuser to pack rocks which were installed system-wide (Backport from svn) --- src/luarocks/manif.lua | 4 ++-- src/luarocks/pack.lua | 36 +++++++++++++++++++++++++----------- 2 files changed, 27 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua index 39351497..c677a22c 100644 --- a/src/luarocks/manif.lua +++ b/src/luarocks/manif.lua @@ -30,7 +30,7 @@ local function save_table(where, name, tbl) return persist.save_from_table(filename, tbl) end -function load_rock_manifest(name, version) +function load_rock_manifest(name, version, root) assert(type(name) == "string") assert(type(version) == "string") @@ -38,7 +38,7 @@ function load_rock_manifest(name, version) if rock_manifest_cache[name_version] then return rock_manifest_cache[name_version].rock_manifest end - local pathname = path.rock_manifest_file(name, version) + local pathname = path.rock_manifest_file(name, version, root) local rock_manifest = persist.load_into_table(pathname) if not rock_manifest then return nil end rock_manifest_cache[name_version] = rock_manifest diff --git a/src/luarocks/pack.lua b/src/luarocks/pack.lua index aaa3d37e..46c00e41 100644 --- a/src/luarocks/pack.lua +++ b/src/luarocks/pack.lua @@ -11,6 +11,7 @@ local cfg = require("luarocks.cfg") local util = require("luarocks.util") local dir = require("luarocks.dir") local manif = require("luarocks.manif") +local search = require("luarocks.search") help_summary = "Create a rock, packing sources or binaries." help_arguments = "{| []}" @@ -82,27 +83,40 @@ end local function pack_binary_rock(name, version) assert(type(name) == "string") assert(type(version) == "string" or not version) - - local versions = rep.get_versions(name) - - if not versions then + + local query = search.make_query(name, version) + query.exact_name = true + local results = {} + for _, tree in ipairs(cfg.rocks_trees) do + search.manifest_search(results, path.rocks_dir(tree), query) + end + if not next(results) then return nil, "'"..name.."' does not seem to be an installed rock." end + + local versions = results[name] + if not version then - if #versions > 1 then + local first = next(versions) + if next(versions, first) then return nil, "Please specify which version of '"..name.."' to pack." end - version = versions[1] + version = first end if not version:match("[^-]+%-%d+") then return nil, "Expected version "..version.." in version-revision format." end - local prefix = path.install_dir(name, version) + + local info = versions[version][1] + + local root = path.root_dir(info.repo) + local prefix = path.install_dir(name, version, root) + if not fs.exists(prefix) then return nil, "'"..name.." "..version.."' does not seem to be an installed rock." end - - local rock_manifest = manif.load_rock_manifest(name, version) + + local rock_manifest = manif.load_rock_manifest(name, version, root) if not rock_manifest then return nil, "rock_manifest file not found for "..name.." "..version.." - not a LuaRocks 2 tree?" end @@ -115,11 +129,11 @@ local function pack_binary_rock(name, version) local is_binary = false if rock_manifest.lib then - copy_back_files(name, version, rock_manifest.lib, cfg.deploy_lib_dir, dir.path(temp_dir, "lib")) + copy_back_files(name, version, rock_manifest.lib, path.deploy_lib_dir(root), dir.path(temp_dir, "lib")) is_binary = true end if rock_manifest.lua then - copy_back_files(name, version, rock_manifest.lua, cfg.deploy_lua_dir, dir.path(temp_dir, "lua")) + copy_back_files(name, version, rock_manifest.lua, path.deploy_lua_dir(root), dir.path(temp_dir, "lua")) end fs.change_dir(temp_dir) -- cgit v1.2.3-55-g6feb