From d0998183ca95077b81fa7c31a48cb74b282fd858 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Wed, 19 Sep 2012 20:27:27 -0300 Subject: Rename luarocks.rep to luarocks.repos. Closes #45. --- src/luarocks/build.lua | 12 +- src/luarocks/install.lua | 12 +- src/luarocks/manif.lua | 10 +- src/luarocks/pack.lua | 4 +- src/luarocks/remove.lua | 4 +- src/luarocks/rep.lua | 313 ----------------------------------------------- src/luarocks/repos.lua | 313 +++++++++++++++++++++++++++++++++++++++++++++++ src/luarocks/search.lua | 8 +- src/luarocks/show.lua | 4 +- 9 files changed, 340 insertions(+), 340 deletions(-) delete mode 100644 src/luarocks/rep.lua create mode 100644 src/luarocks/repos.lua (limited to 'src') diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index e9b3adc1..6ffa0e79 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua @@ -6,7 +6,7 @@ module("luarocks.build", package.seeall) local pack = require("luarocks.pack") local path = require("luarocks.path") local util = require("luarocks.util") -local rep = require("luarocks.rep") +local repos = require("luarocks.repos") local fetch = require("luarocks.fetch") local fs = require("luarocks.fs") local dir = require("luarocks.dir") @@ -142,8 +142,8 @@ function build_rockspec(rockspec_file, need_to_fetch, minimal_mode, no_deps) end local name, version = rockspec.name, rockspec.version - if rep.is_installed(name, version) then - rep.delete_version(name, version) + if repos.is_installed(name, version) then + repos.delete_version(name, version) end if not minimal_mode then @@ -242,15 +242,15 @@ function build_rockspec(rockspec_file, need_to_fetch, minimal_mode, no_deps) ok, err = manif.make_rock_manifest(name, version) if err then return nil, err end - ok, err = rep.deploy_files(name, version, rep.should_wrap_bin_scripts(rockspec)) + ok, err = repos.deploy_files(name, version, repos.should_wrap_bin_scripts(rockspec)) if err then return nil, err end util.remove_scheduled_function(rollback) rollback = util.schedule_function(function() - rep.delete_version(name, version) + repos.delete_version(name, version) end) - ok, err = rep.run_hook(rockspec, "post_install") + ok, err = repos.run_hook(rockspec, "post_install") if err then return nil, err end ok, err = manif.update_manifest(name, version) diff --git a/src/luarocks/install.lua b/src/luarocks/install.lua index 0a779b86..6b5ea85f 100644 --- a/src/luarocks/install.lua +++ b/src/luarocks/install.lua @@ -4,7 +4,7 @@ module("luarocks.install", package.seeall) local path = require("luarocks.path") -local rep = require("luarocks.rep") +local repos = require("luarocks.repos") local fetch = require("luarocks.fetch") local util = require("luarocks.util") local fs = require("luarocks.fs") @@ -37,8 +37,8 @@ function install_binary_rock(rock_file, no_deps) if arch ~= "all" and arch ~= cfg.arch then return nil, "Incompatible architecture "..arch, "arch" end - if rep.is_installed(name, version) then - rep.delete_version(name, version) + if repos.is_installed(name, version) then + repos.delete_version(name, version) end local rollback = util.schedule_function(function() @@ -77,15 +77,15 @@ function install_binary_rock(rock_file, no_deps) wrap_bin_scripts = false end - ok, err = rep.deploy_files(name, version, rep.should_wrap_bin_scripts(rockspec)) + ok, err = repos.deploy_files(name, version, repos.should_wrap_bin_scripts(rockspec)) if err then return nil, err end util.remove_scheduled_function(rollback) rollback = util.schedule_function(function() - rep.delete_version(name, version) + repos.delete_version(name, version) end) - ok, err = rep.run_hook(rockspec, "post_install") + ok, err = repos.run_hook(rockspec, "post_install") if err then return nil, err end ok, err = manif.update_manifest(name, version) diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua index 6b05b749..2c745f0b 100644 --- a/src/luarocks/manif.lua +++ b/src/luarocks/manif.lua @@ -14,7 +14,7 @@ local search = require("luarocks.search") local util = require("luarocks.util") local cfg = require("luarocks.cfg") local path = require("luarocks.path") -local rep = require("luarocks.rep") +local repos = require("luarocks.repos") local deps = require("luarocks.deps") rock_manifest_cache = {} @@ -187,9 +187,9 @@ end -- @param manifest table: a manifest table. local function update_dependencies(manifest) for pkg, versions in pairs(manifest.repository) do - for version, repos in pairs(versions) do + for version, repositories in pairs(versions) do local current = pkg.." "..version - for _, repo in ipairs(repos) do + for _, repo in ipairs(repositories) do if repo.arch == "installed" then local missing repo.dependencies, missing = deps.scan_deps({}, {}, manifest, pkg, version) @@ -230,8 +230,8 @@ local function store_results(results, manifest) if not rock_manifest then return nil, "rock_manifest file not found for "..name.." "..version.." - not a LuaRocks 2 tree?" end - entrytable.modules = store_package_items(rep.package_modules, name, version, manifest.modules) - entrytable.commands = store_package_items(rep.package_commands, name, version, manifest.commands) + entrytable.modules = store_package_items(repos.package_modules, name, version, manifest.modules) + entrytable.commands = store_package_items(repos.package_commands, name, version, manifest.commands) end table.insert(versiontable, entrytable) end diff --git a/src/luarocks/pack.lua b/src/luarocks/pack.lua index f7a7ad12..d8f0b2ef 100644 --- a/src/luarocks/pack.lua +++ b/src/luarocks/pack.lua @@ -4,7 +4,7 @@ module("luarocks.pack", package.seeall) local path = require("luarocks.path") -local rep = require("luarocks.rep") +local repos = require("luarocks.repos") local fetch = require("luarocks.fetch") local fs = require("luarocks.fs") local cfg = require("luarocks.cfg") @@ -137,7 +137,7 @@ local function do_pack_binary_rock(name, version) end fs.change_dir(temp_dir) - if not is_binary and not rep.has_binaries(name, version) then + if not is_binary and not repos.has_binaries(name, version) then rock_file = rock_file:gsub("%."..cfg.arch:gsub("%-","%%-").."%.", ".all.") end fs.delete(rock_file) diff --git a/src/luarocks/remove.lua b/src/luarocks/remove.lua index b22d1ab6..a9d97540 100644 --- a/src/luarocks/remove.lua +++ b/src/luarocks/remove.lua @@ -6,7 +6,7 @@ module("luarocks.remove", package.seeall) local search = require("luarocks.search") local deps = require("luarocks.deps") local fetch = require("luarocks.fetch") -local rep = require("luarocks.rep") +local repos = require("luarocks.repos") local path = require("luarocks.path") local util = require("luarocks.util") local cfg = require("luarocks.cfg") @@ -62,7 +62,7 @@ local function delete_versions(name, versions) for version, _ in pairs(versions) do util.printout("Removing "..name.." "..version.."...") - local ok, err = rep.delete_version(name, version) + local ok, err = repos.delete_version(name, version) if not ok then return nil, err end end diff --git a/src/luarocks/rep.lua b/src/luarocks/rep.lua deleted file mode 100644 index 5bb5fed5..00000000 --- a/src/luarocks/rep.lua +++ /dev/null @@ -1,313 +0,0 @@ - ---- Functions for managing the repository on disk. -module("luarocks.rep", package.seeall) - -local fs = require("luarocks.fs") -local path = require("luarocks.path") -local cfg = require("luarocks.cfg") -local util = require("luarocks.util") -local dir = require("luarocks.dir") -local manif = require("luarocks.manif") -local deps = require("luarocks.deps") - ---- Get all installed versions of a package. --- @param name string: a package name. --- @return table or nil: An array of strings listing installed --- versions of a package, or nil if none is available. -function get_versions(name) - assert(type(name) == "string") - - local dirs = fs.list_dir(path.versions_dir(name)) - return (dirs and #dirs > 0) and dirs or nil -end - ---- Check if a package exists in a local repository. --- Version numbers are compared as exact string comparison. --- @param name string: name of package --- @param version string: package version in string format --- @return boolean: true if a package is installed, --- false otherwise. -function is_installed(name, version) - assert(type(name) == "string") - assert(type(version) == "string") - - return fs.is_dir(path.install_dir(name, version)) -end - -local function recurse_rock_manifest_tree(file_tree, action) - assert(type(file_tree) == "table") - assert(type(action) == "function") - local function do_recurse_rock_manifest_tree(tree, parent_path, parent_module) - - for file, sub in pairs(tree) do - if type(sub) == "table" then - local ok, err = do_recurse_rock_manifest_tree(sub, parent_path..file.."/", parent_module..file..".") - if not ok then return nil, err end - else - local ok, err = action(parent_path, parent_module, file) - if not ok then return nil, err end - end - end - return true - end - return do_recurse_rock_manifest_tree(file_tree, "", "") -end - -local function store_package_data(result, name, sub, prefix) - assert(type(result) == "table") - assert(type(name) == "string") - assert(type(sub) == "table" or type(sub) == "string") - assert(type(prefix) == "string") - - if type(sub) == "table" then - for sname, ssub in pairs(sub) do - store_package_data(result, sname, ssub, prefix..name.."/") - end - elseif type(sub) == "string" then - local pathname = prefix..name - result[path.path_to_module(pathname)] = pathname - end -end - -local function store_package_data(result, name, file_tree) - if not file_tree then return end - return recurse_rock_manifest_tree(file_tree, - function(parent_path, parent_module, file) - local pathname = parent_path..file - result[path.path_to_module(pathname)] = pathname - return true - end - ) -end - ---- Obtain a list of modules within an installed package. --- @param package string: The package name; for example "luasocket" --- @param version string: The exact version number including revision; --- for example "2.0.1-1". --- @return table: A table of modules where keys are module identifiers --- in "foo.bar" format and values are pathnames in architecture-dependent --- "foo/bar.so" format. If no modules are found or if package or version --- are invalid, an empty table is returned. -function package_modules(package, version) - assert(type(package) == "string") - assert(type(version) == "string") - - local result = {} - local rock_manifest = manif.load_rock_manifest(package, version) - store_package_data(result, package, rock_manifest.lib) - store_package_data(result, package, rock_manifest.lua) - return result -end - ---- Obtain a list of command-line scripts within an installed package. --- @param package string: The package name; for example "luasocket" --- @param version string: The exact version number including revision; --- for example "2.0.1-1". --- @return table: A table of items where keys are command names --- as strings and values are pathnames in architecture-dependent --- ".../bin/foo" format. If no modules are found or if package or version --- are invalid, an empty table is returned. -function package_commands(package, version) - assert(type(package) == "string") - assert(type(version) == "string") - - local result = {} - local rock_manifest = manif.load_rock_manifest(package, version) - store_package_data(result, package, rock_manifest.bin) - return result -end - - ---- Check if a rock contains binary executables. --- @param name string: name of an installed rock --- @param version string: version of an installed rock --- @return boolean: returns true if rock contains platform-specific --- binary executables, or false if it is a pure-Lua rock. -function has_binaries(name, version) - assert(type(name) == "string") - assert(type(version) == "string") - - local rock_manifest = manif.load_rock_manifest(name, version) - if rock_manifest.bin then - for name, md5 in pairs(rock_manifest.bin) do - -- TODO verify that it is the same file. If it isn't, find the actual command. - if fs.is_actual_binary(dir.path(cfg.deploy_bin_dir, name)) then - return true - end - end - end - return false -end - -function run_hook(rockspec, hook_name) - assert(type(rockspec) == "table") - assert(type(hook_name) == "string") - - local hooks = rockspec.hooks - if not hooks then - return true - end - if not hooks.substituted_variables then - util.variable_substitutions(hooks, rockspec.variables) - hooks.substituted_variables = true - end - local hook = hooks[hook_name] - if hook then - util.printout(hook) - if not fs.execute(hook) then - return nil, "Failed running "..hook_name.." hook." - end - end - return true -end - -local function install_binary(source, target) - assert(type(source) == "string") - assert(type(target) == "string") - - local match = source:match("%.lua$") - local file, ok, err - if not match then - file = io.open(source) - end - if match or (file and file:read():match("^#!.*lua.*")) then - ok, err = fs.wrap_script(source, target) - else - ok, err = fs.copy_binary(source, target) - end - if file then file:close() end - return ok, err -end - -local function resolve_conflict(target, deploy_dir, name, version) - local cname, cversion = manif.find_current_provider(target) - if not cname then - return nil, cversion - end - if name ~= cname or deps.compare_versions(version, cversion) then - local versioned = path.versioned_name(target, deploy_dir, cname, cversion) - fs.make_dir(dir.dir_name(versioned)) - fs.move(target, versioned) - return target - else - return path.versioned_name(target, deploy_dir, name, version) - end -end - -function should_wrap_bin_scripts(rockspec) - assert(type(rockspec) == "table") - - if cfg.wrap_bin_scripts ~= nil then - return cfg.wrap_bin_scripts - end - if rockspec.deploy and rockspec.deploy.wrap_bin_scripts == false then - return false - end - return true -end - -function deploy_files(name, version, wrap_bin_scripts) - assert(type(name) == "string") - assert(type(version) == "string") - assert(type(wrap_bin_scripts) == "boolean") - - local function deploy_file_tree(file_tree, source_dir, deploy_dir, move_fn) - if not move_fn then - move_fn = fs.move - end - return recurse_rock_manifest_tree(file_tree, - function(parent_path, parent_module, file) - local source = dir.path(source_dir, parent_path, file) - local target = dir.path(deploy_dir, parent_path, file) - local ok, err - if fs.exists(target) then - local new_target, err = resolve_conflict(target, deploy_dir, name, version) - if err == "untracked" then - fs.delete(target) - elseif err then - return nil, err.." Cannot install new version." - else - target = new_target - end - end - fs.make_dir(dir.dir_name(target)) - ok, err = move_fn(source, target) - fs.remove_dir_tree_if_empty(dir.dir_name(source)) - if not ok then return nil, err end - return true - end - ) - end - - local rock_manifest = manif.load_rock_manifest(name, version) - - local ok, err = true - if rock_manifest.bin then - local move_bin_fn = wrap_bin_scripts and install_binary or fs.copy_binary - ok, err = deploy_file_tree(rock_manifest.bin, path.bin_dir(name, version), cfg.deploy_bin_dir, move_bin_fn) - end - if ok and rock_manifest.lua then - ok, err = deploy_file_tree(rock_manifest.lua, path.lua_dir(name, version), cfg.deploy_lua_dir) - end - if ok and rock_manifest.lib then - ok, err = deploy_file_tree(rock_manifest.lib, path.lib_dir(name, version), cfg.deploy_lib_dir) - end - return ok, err -end - ---- Delete a package from the local repository. --- Version numbers are compared as exact string comparison. --- @param name string: name of package --- @param version string: package version in string format -function delete_version(name, version) - assert(type(name) == "string") - assert(type(version) == "string") - - local function delete_deployed_file_tree(file_tree, deploy_dir) - return recurse_rock_manifest_tree(file_tree, - function(parent_path, parent_module, file) - local target = dir.path(deploy_dir, parent_path, file) - local versioned = path.versioned_name(target, deploy_dir, name, version) - if fs.exists(versioned) then - local ok = fs.delete(versioned) - fs.remove_dir_tree_if_empty(dir.dir_name(versioned)) - if not ok then return nil, "Failed deleting "..versioned end - else - local ok = fs.delete(target) - local next_name, next_version = manif.find_next_provider(target) - if next_name then - local versioned = path.versioned_name(target, deploy_dir, next_name, next_version) - fs.move(versioned, target) - fs.remove_dir_tree_if_empty(dir.dir_name(versioned)) - end - fs.remove_dir_tree_if_empty(dir.dir_name(target)) - if not ok then return nil, "Failed deleting "..target end - end - return true - end - ) - end - - local rock_manifest = manif.load_rock_manifest(name, version) - if not rock_manifest then - return nil, "rock_manifest file not found for "..name.." "..version.." - not a LuaRocks 2 tree?" - end - - local ok, err = true - if rock_manifest.bin then - ok, err = delete_deployed_file_tree(rock_manifest.bin, cfg.deploy_bin_dir) - end - if ok and rock_manifest.lua then - ok, err = delete_deployed_file_tree(rock_manifest.lua, cfg.deploy_lua_dir) - end - if ok and rock_manifest.lib then - ok, err = delete_deployed_file_tree(rock_manifest.lib, cfg.deploy_lib_dir) - end - if err then return nil, err end - - fs.delete(path.install_dir(name, version)) - if not get_versions(name) then - fs.delete(dir.path(cfg.rocks_dir, name)) - end - return true -end diff --git a/src/luarocks/repos.lua b/src/luarocks/repos.lua new file mode 100644 index 00000000..e6f0c5f7 --- /dev/null +++ b/src/luarocks/repos.lua @@ -0,0 +1,313 @@ + +--- Functions for managing the repository on disk. +module("luarocks.repos", package.seeall) + +local fs = require("luarocks.fs") +local path = require("luarocks.path") +local cfg = require("luarocks.cfg") +local util = require("luarocks.util") +local dir = require("luarocks.dir") +local manif = require("luarocks.manif") +local deps = require("luarocks.deps") + +--- Get all installed versions of a package. +-- @param name string: a package name. +-- @return table or nil: An array of strings listing installed +-- versions of a package, or nil if none is available. +function get_versions(name) + assert(type(name) == "string") + + local dirs = fs.list_dir(path.versions_dir(name)) + return (dirs and #dirs > 0) and dirs or nil +end + +--- Check if a package exists in a local repository. +-- Version numbers are compared as exact string comparison. +-- @param name string: name of package +-- @param version string: package version in string format +-- @return boolean: true if a package is installed, +-- false otherwise. +function is_installed(name, version) + assert(type(name) == "string") + assert(type(version) == "string") + + return fs.is_dir(path.install_dir(name, version)) +end + +local function recurse_rock_manifest_tree(file_tree, action) + assert(type(file_tree) == "table") + assert(type(action) == "function") + local function do_recurse_rock_manifest_tree(tree, parent_path, parent_module) + + for file, sub in pairs(tree) do + if type(sub) == "table" then + local ok, err = do_recurse_rock_manifest_tree(sub, parent_path..file.."/", parent_module..file..".") + if not ok then return nil, err end + else + local ok, err = action(parent_path, parent_module, file) + if not ok then return nil, err end + end + end + return true + end + return do_recurse_rock_manifest_tree(file_tree, "", "") +end + +local function store_package_data(result, name, sub, prefix) + assert(type(result) == "table") + assert(type(name) == "string") + assert(type(sub) == "table" or type(sub) == "string") + assert(type(prefix) == "string") + + if type(sub) == "table" then + for sname, ssub in pairs(sub) do + store_package_data(result, sname, ssub, prefix..name.."/") + end + elseif type(sub) == "string" then + local pathname = prefix..name + result[path.path_to_module(pathname)] = pathname + end +end + +local function store_package_data(result, name, file_tree) + if not file_tree then return end + return recurse_rock_manifest_tree(file_tree, + function(parent_path, parent_module, file) + local pathname = parent_path..file + result[path.path_to_module(pathname)] = pathname + return true + end + ) +end + +--- Obtain a list of modules within an installed package. +-- @param package string: The package name; for example "luasocket" +-- @param version string: The exact version number including revision; +-- for example "2.0.1-1". +-- @return table: A table of modules where keys are module identifiers +-- in "foo.bar" format and values are pathnames in architecture-dependent +-- "foo/bar.so" format. If no modules are found or if package or version +-- are invalid, an empty table is returned. +function package_modules(package, version) + assert(type(package) == "string") + assert(type(version) == "string") + + local result = {} + local rock_manifest = manif.load_rock_manifest(package, version) + store_package_data(result, package, rock_manifest.lib) + store_package_data(result, package, rock_manifest.lua) + return result +end + +--- Obtain a list of command-line scripts within an installed package. +-- @param package string: The package name; for example "luasocket" +-- @param version string: The exact version number including revision; +-- for example "2.0.1-1". +-- @return table: A table of items where keys are command names +-- as strings and values are pathnames in architecture-dependent +-- ".../bin/foo" format. If no modules are found or if package or version +-- are invalid, an empty table is returned. +function package_commands(package, version) + assert(type(package) == "string") + assert(type(version) == "string") + + local result = {} + local rock_manifest = manif.load_rock_manifest(package, version) + store_package_data(result, package, rock_manifest.bin) + return result +end + + +--- Check if a rock contains binary executables. +-- @param name string: name of an installed rock +-- @param version string: version of an installed rock +-- @return boolean: returns true if rock contains platform-specific +-- binary executables, or false if it is a pure-Lua rock. +function has_binaries(name, version) + assert(type(name) == "string") + assert(type(version) == "string") + + local rock_manifest = manif.load_rock_manifest(name, version) + if rock_manifest.bin then + for name, md5 in pairs(rock_manifest.bin) do + -- TODO verify that it is the same file. If it isn't, find the actual command. + if fs.is_actual_binary(dir.path(cfg.deploy_bin_dir, name)) then + return true + end + end + end + return false +end + +function run_hook(rockspec, hook_name) + assert(type(rockspec) == "table") + assert(type(hook_name) == "string") + + local hooks = rockspec.hooks + if not hooks then + return true + end + if not hooks.substituted_variables then + util.variable_substitutions(hooks, rockspec.variables) + hooks.substituted_variables = true + end + local hook = hooks[hook_name] + if hook then + util.printout(hook) + if not fs.execute(hook) then + return nil, "Failed running "..hook_name.." hook." + end + end + return true +end + +local function install_binary(source, target) + assert(type(source) == "string") + assert(type(target) == "string") + + local match = source:match("%.lua$") + local file, ok, err + if not match then + file = io.open(source) + end + if match or (file and file:read():match("^#!.*lua.*")) then + ok, err = fs.wrap_script(source, target) + else + ok, err = fs.copy_binary(source, target) + end + if file then file:close() end + return ok, err +end + +local function resolve_conflict(target, deploy_dir, name, version) + local cname, cversion = manif.find_current_provider(target) + if not cname then + return nil, cversion + end + if name ~= cname or deps.compare_versions(version, cversion) then + local versioned = path.versioned_name(target, deploy_dir, cname, cversion) + fs.make_dir(dir.dir_name(versioned)) + fs.move(target, versioned) + return target + else + return path.versioned_name(target, deploy_dir, name, version) + end +end + +function should_wrap_bin_scripts(rockspec) + assert(type(rockspec) == "table") + + if cfg.wrap_bin_scripts ~= nil then + return cfg.wrap_bin_scripts + end + if rockspec.deploy and rockspec.deploy.wrap_bin_scripts == false then + return false + end + return true +end + +function deploy_files(name, version, wrap_bin_scripts) + assert(type(name) == "string") + assert(type(version) == "string") + assert(type(wrap_bin_scripts) == "boolean") + + local function deploy_file_tree(file_tree, source_dir, deploy_dir, move_fn) + if not move_fn then + move_fn = fs.move + end + return recurse_rock_manifest_tree(file_tree, + function(parent_path, parent_module, file) + local source = dir.path(source_dir, parent_path, file) + local target = dir.path(deploy_dir, parent_path, file) + local ok, err + if fs.exists(target) then + local new_target, err = resolve_conflict(target, deploy_dir, name, version) + if err == "untracked" then + fs.delete(target) + elseif err then + return nil, err.." Cannot install new version." + else + target = new_target + end + end + fs.make_dir(dir.dir_name(target)) + ok, err = move_fn(source, target) + fs.remove_dir_tree_if_empty(dir.dir_name(source)) + if not ok then return nil, err end + return true + end + ) + end + + local rock_manifest = manif.load_rock_manifest(name, version) + + local ok, err = true + if rock_manifest.bin then + local move_bin_fn = wrap_bin_scripts and install_binary or fs.copy_binary + ok, err = deploy_file_tree(rock_manifest.bin, path.bin_dir(name, version), cfg.deploy_bin_dir, move_bin_fn) + end + if ok and rock_manifest.lua then + ok, err = deploy_file_tree(rock_manifest.lua, path.lua_dir(name, version), cfg.deploy_lua_dir) + end + if ok and rock_manifest.lib then + ok, err = deploy_file_tree(rock_manifest.lib, path.lib_dir(name, version), cfg.deploy_lib_dir) + end + return ok, err +end + +--- Delete a package from the local repository. +-- Version numbers are compared as exact string comparison. +-- @param name string: name of package +-- @param version string: package version in string format +function delete_version(name, version) + assert(type(name) == "string") + assert(type(version) == "string") + + local function delete_deployed_file_tree(file_tree, deploy_dir) + return recurse_rock_manifest_tree(file_tree, + function(parent_path, parent_module, file) + local target = dir.path(deploy_dir, parent_path, file) + local versioned = path.versioned_name(target, deploy_dir, name, version) + if fs.exists(versioned) then + local ok = fs.delete(versioned) + fs.remove_dir_tree_if_empty(dir.dir_name(versioned)) + if not ok then return nil, "Failed deleting "..versioned end + else + local ok = fs.delete(target) + local next_name, next_version = manif.find_next_provider(target) + if next_name then + local versioned = path.versioned_name(target, deploy_dir, next_name, next_version) + fs.move(versioned, target) + fs.remove_dir_tree_if_empty(dir.dir_name(versioned)) + end + fs.remove_dir_tree_if_empty(dir.dir_name(target)) + if not ok then return nil, "Failed deleting "..target end + end + return true + end + ) + end + + local rock_manifest = manif.load_rock_manifest(name, version) + if not rock_manifest then + return nil, "rock_manifest file not found for "..name.." "..version.." - not a LuaRocks 2 tree?" + end + + local ok, err = true + if rock_manifest.bin then + ok, err = delete_deployed_file_tree(rock_manifest.bin, cfg.deploy_bin_dir) + end + if ok and rock_manifest.lua then + ok, err = delete_deployed_file_tree(rock_manifest.lua, cfg.deploy_lua_dir) + end + if ok and rock_manifest.lib then + ok, err = delete_deployed_file_tree(rock_manifest.lib, cfg.deploy_lib_dir) + end + if err then return nil, err end + + fs.delete(path.install_dir(name, version)) + if not get_versions(name) then + fs.delete(dir.path(cfg.rocks_dir, name)) + end + return true +end diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua index 9c53632a..4e0318c7 100644 --- a/src/luarocks/search.lua +++ b/src/luarocks/search.lua @@ -297,9 +297,9 @@ function print_results(results, show_repo, long) for package, versions in util.sortedpairs(results) do util.printout(package) - for version, repos in util.sortedpairs(versions, deps.compare_versions) do + for version, repositories in util.sortedpairs(versions, deps.compare_versions) do if show_repo then - for _, repo in ipairs(repos) do + for _, repo in ipairs(repositories) do util.printout(" "..version.." ("..repo.arch..") - "..repo.repo) end else @@ -319,8 +319,8 @@ end local function split_source_and_binary_results(results) local sources, binaries = {}, {} for name, versions in pairs(results) do - for version, repos in pairs(versions) do - for _, repo in ipairs(repos) do + for version, repositories in pairs(versions) do + for _, repo in ipairs(repositories) do local where = sources if repo.arch == "all" or repo.arch == cfg.arch then where = binaries diff --git a/src/luarocks/show.lua b/src/luarocks/show.lua index 7255ea63..5a052b58 100644 --- a/src/luarocks/show.lua +++ b/src/luarocks/show.lua @@ -82,9 +82,9 @@ function run(...) local package, versions = util.sortedpairs(results)() --question: what do we do about multiple versions? This should --give us the latest version on the last repo (which is usually the global one) - for vs, repos in util.sortedpairs(versions, deps.compare_versions) do + for vs, repositories in util.sortedpairs(versions, deps.compare_versions) do if not version then version = vs end - for _, rp in ipairs(repos) do repo_url = rp.repo end + for _, rp in ipairs(repositories) do repo_url = rp.repo end end -- cgit v1.2.3-55-g6feb