| |
|
| |
|
| | local repos = {}
|
| |
|
| | local fs = require("luarocks.fs")
|
| | local path = require("luarocks.path")
|
| | local cfg = require("luarocks.core.cfg")
|
| | local util = require("luarocks.util")
|
| | local dir = require("luarocks.dir")
|
| | local manif = require("luarocks.manif")
|
| | local vers = require("luarocks.core.vers")
|
| | local E = {}
|
| |
|
| | local unpack = unpack or table.unpack
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | local function get_provided_item(deploy_type, file_path)
|
| | assert(type(deploy_type) == "string")
|
| | assert(type(file_path) == "string")
|
| | local item_type = deploy_type == "bin" and "command" or "module"
|
| | local item_name = item_type == "command" and file_path or path.path_to_module(file_path)
|
| | return item_type, item_name
|
| | end
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | local function get_installed_versions(name)
|
| | assert(type(name) == "string" and not name:match("/"))
|
| |
|
| | local dirs = fs.list_dir(path.versions_dir(name))
|
| | return (dirs and #dirs > 0) and dirs or nil
|
| | end
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | function repos.is_installed(name, version)
|
| | assert(type(name) == "string" and not name:match("/"))
|
| | assert(type(version) == "string")
|
| |
|
| | return fs.is_dir(path.install_dir(name, version))
|
| | end
|
| |
|
| | function repos.recurse_rock_manifest_entry(entry, action)
|
| | assert(type(action) == "function")
|
| |
|
| | if entry == nil then
|
| | return true
|
| | end
|
| |
|
| | local function do_recurse_rock_manifest_entry(tree, parent_path)
|
| |
|
| | for file, sub in pairs(tree) do
|
| | local sub_path = (parent_path and (parent_path .. "/") or "") .. file
|
| | local ok, err
|
| |
|
| | if type(sub) == "table" then
|
| | ok, err = do_recurse_rock_manifest_entry(sub, sub_path)
|
| | else
|
| | ok, err = action(sub_path)
|
| | end
|
| |
|
| | if err then return nil, err end
|
| | end
|
| | return true
|
| | end
|
| | return do_recurse_rock_manifest_entry(entry)
|
| | end
|
| |
|
| | local function store_package_data(result, rock_manifest, deploy_type)
|
| | if rock_manifest[deploy_type] then
|
| | repos.recurse_rock_manifest_entry(rock_manifest[deploy_type], function(file_path)
|
| | local _, item_name = get_provided_item(deploy_type, file_path)
|
| | result[item_name] = file_path
|
| | return true
|
| | end)
|
| | end
|
| | end
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | function repos.package_modules(name, version)
|
| | assert(type(name) == "string" and not name:match("/"))
|
| | assert(type(version) == "string")
|
| |
|
| | local result = {}
|
| | local rock_manifest = manif.load_rock_manifest(name, version)
|
| | if not rock_manifest then return result end
|
| | store_package_data(result, rock_manifest, "lib")
|
| | store_package_data(result, rock_manifest, "lua")
|
| | return result
|
| | end
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | function repos.package_commands(name, version)
|
| | assert(type(name) == "string" and not name:match("/"))
|
| | assert(type(version) == "string")
|
| |
|
| | local result = {}
|
| | local rock_manifest = manif.load_rock_manifest(name, version)
|
| | if not rock_manifest then return result end
|
| | store_package_data(result, rock_manifest, "bin")
|
| | return result
|
| | end
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | function repos.has_binaries(name, version)
|
| | assert(type(name) == "string" and not name:match("/"))
|
| | assert(type(version) == "string")
|
| |
|
| | local rock_manifest = manif.load_rock_manifest(name, version)
|
| | if rock_manifest and rock_manifest.bin then
|
| | for bin_name, md5 in pairs(rock_manifest.bin) do
|
| |
|
| | if fs.is_actual_binary(dir.path(cfg.deploy_bin_dir, bin_name)) then
|
| | return true
|
| | end
|
| | end
|
| | end
|
| | return false
|
| | end
|
| |
|
| | function repos.run_hook(rockspec, hook_name)
|
| | assert(rockspec:type() == "rockspec")
|
| | assert(type(hook_name) == "string")
|
| |
|
| | local hooks = rockspec.hooks
|
| | if not hooks then
|
| | return true
|
| | end
|
| |
|
| | if cfg.hooks_enabled == false then
|
| | return nil, "This rockspec contains hooks, which are blocked by the 'hooks_enabled' setting in your LuaRocks configuration."
|
| | 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
|
| |
|
| | function repos.should_wrap_bin_scripts(rockspec)
|
| | assert(rockspec:type() == "rockspec")
|
| |
|
| | 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
|
| |
|
| | local function find_suffixed(file, suffix)
|
| | local filenames = {file}
|
| | if suffix and suffix ~= "" then
|
| | table.insert(filenames, 1, file .. suffix)
|
| | end
|
| |
|
| | for _, filename in ipairs(filenames) do
|
| | if fs.exists(filename) then
|
| | return filename
|
| | end
|
| | end
|
| |
|
| | return nil, table.concat(filenames, ", ") .. " not found"
|
| | end
|
| |
|
| | local function check_suffix(filename, suffix)
|
| | local suffixed_filename, err = find_suffixed(filename, suffix)
|
| | if not suffixed_filename then
|
| | return ""
|
| | end
|
| | return suffixed_filename:sub(#filename + 1)
|
| | end
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | local function get_deploy_paths(name, version, deploy_type, file_path, repo)
|
| | assert(type(name) == "string")
|
| | assert(type(version) == "string")
|
| | assert(type(deploy_type) == "string")
|
| | assert(type(file_path) == "string")
|
| |
|
| | 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 { nv = non_versioned, v = versioned }
|
| | end
|
| |
|
| | local function check_spot_if_available(name, version, deploy_type, file_path)
|
| | local item_type, item_name = get_provided_item(deploy_type, file_path)
|
| | local cur_name, cur_version = manif.get_current_provider(item_type, item_name)
|
| | if (not cur_name)
|
| | or (name < cur_name)
|
| | or (name == cur_name and (version == cur_version
|
| | or vers.compare_versions(version, cur_version))) then
|
| | return "nv", cur_name, cur_version, item_name
|
| | else
|
| |
|
| | return "v", cur_name, cur_version, item_name
|
| | end
|
| | end
|
| |
|
| | local function backup_existing(should_backup, target)
|
| | if not should_backup then
|
| | fs.delete(target)
|
| | return
|
| | end
|
| | if fs.exists(target) then
|
| | local backup = target
|
| | repeat
|
| | backup = backup.."~"
|
| | until not fs.exists(backup)
|
| |
|
| | util.warning(target.." is not tracked by this installation of LuaRocks. Moving it to "..backup)
|
| | local move_ok, move_err = fs.move(target, backup)
|
| | if not move_ok then
|
| | return nil, move_err
|
| | end
|
| | end
|
| | end
|
| |
|
| | local function op_install(op)
|
| | local ok, err = fs.make_dir(dir.dir_name(op.dst))
|
| | if not ok then
|
| | return nil, err
|
| | end
|
| |
|
| | ok, err = op.fn(op.src, op.dst, op.backup)
|
| | if not ok then
|
| | return nil, err
|
| | end
|
| |
|
| | fs.remove_dir_tree_if_empty(dir.dir_name(op.src))
|
| | end
|
| |
|
| | local function op_rename(op)
|
| | if op.suffix then
|
| | local suffix = check_suffix(op.src, op.suffix)
|
| | op.src = op.src .. suffix
|
| | op.dst = op.dst .. suffix
|
| | end
|
| |
|
| | if fs.exists(op.src) then
|
| | fs.make_dir(dir.dir_name(op.dst))
|
| | fs.delete(op.dst)
|
| | local ok, err = fs.move(op.src, op.dst)
|
| | fs.remove_dir_tree_if_empty(dir.dir_name(op.src))
|
| | return ok, err
|
| | else
|
| | return true
|
| | end
|
| | end
|
| |
|
| | local function op_delete(op)
|
| | if op.suffix then
|
| | local suffix = check_suffix(op.name, op.suffix)
|
| | op.name = op.name .. suffix
|
| | end
|
| |
|
| | local ok, err = fs.delete(op.name)
|
| | fs.remove_dir_tree_if_empty(dir.dir_name(op.name))
|
| | return ok, err
|
| | end
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | function repos.deploy_files(name, version, wrap_bin_scripts, deps_mode)
|
| | assert(type(name) == "string" and not name:match("/"))
|
| | assert(type(version) == "string")
|
| | assert(type(wrap_bin_scripts) == "boolean")
|
| |
|
| | local rock_manifest, load_err = manif.load_rock_manifest(name, version)
|
| | if not rock_manifest then return nil, load_err end
|
| |
|
| | local repo = cfg.root_dir
|
| | local renames = {}
|
| | local installs = {}
|
| |
|
| | local function install_binary(source, target, should_backup)
|
| | if wrap_bin_scripts and fs.is_lua(source) then
|
| | backup_existing(should_backup, target .. (cfg.wrapper_suffix or ""))
|
| | return fs.wrap_script(source, target, deps_mode, name, version)
|
| | else
|
| | backup_existing(should_backup, target)
|
| | return fs.copy_binary(source, target)
|
| | end
|
| | end
|
| |
|
| | local function move_lua(source, target, should_backup)
|
| | backup_existing(should_backup, target)
|
| | return fs.move(source, target, "read")
|
| | end
|
| |
|
| | local function move_lib(source, target, should_backup)
|
| | backup_existing(should_backup, target)
|
| | return fs.move(source, target, "exec")
|
| | end
|
| |
|
| | if rock_manifest.bin then
|
| | local source_dir = path.bin_dir(name, version)
|
| | repos.recurse_rock_manifest_entry(rock_manifest.bin, function(file_path)
|
| | local source = dir.path(source_dir, file_path)
|
| | local paths = get_deploy_paths(name, version, "bin", file_path, repo)
|
| | local mode, cur_name, cur_version = check_spot_if_available(name, version, "bin", file_path)
|
| |
|
| | if mode == "nv" and cur_name then
|
| | local cur_paths = get_deploy_paths(cur_name, cur_version, "bin", file_path, repo)
|
| | table.insert(renames, { src = cur_paths.nv, dst = cur_paths.v, suffix = cfg.wrapper_suffix })
|
| | end
|
| | local backup = name ~= cur_name or version ~= cur_version
|
| | table.insert(installs, { fn = install_binary, src = source, dst = mode == "nv" and paths.nv or paths.v, backup = backup })
|
| | end)
|
| | end
|
| |
|
| | if rock_manifest.lua then
|
| | local source_dir = path.lua_dir(name, version)
|
| | repos.recurse_rock_manifest_entry(rock_manifest.lua, function(file_path)
|
| | local source = dir.path(source_dir, file_path)
|
| | local paths = get_deploy_paths(name, version, "lua", file_path, repo)
|
| | local mode, cur_name, cur_version = check_spot_if_available(name, version, "lua", file_path)
|
| |
|
| | if mode == "nv" and cur_name then
|
| | local cur_paths = get_deploy_paths(cur_name, cur_version, "lua", file_path, repo)
|
| | table.insert(renames, { src = cur_paths.nv, dst = cur_paths.v })
|
| | cur_paths = get_deploy_paths(cur_name, cur_version, "lib", file_path:gsub("%.lua$", "." .. cfg.lib_extension), repo)
|
| | table.insert(renames, { src = cur_paths.nv, dst = cur_paths.v })
|
| | end
|
| | local backup = name ~= cur_name or version ~= cur_version
|
| | table.insert(installs, { fn = move_lua, src = source, dst = mode == "nv" and paths.nv or paths.v, backup = backup })
|
| | end)
|
| | end
|
| |
|
| | if rock_manifest.lib then
|
| | local source_dir = path.lib_dir(name, version)
|
| | repos.recurse_rock_manifest_entry(rock_manifest.lib, function(file_path)
|
| | local source = dir.path(source_dir, file_path)
|
| | local paths = get_deploy_paths(name, version, "lib", file_path, repo)
|
| | local mode, cur_name, cur_version = check_spot_if_available(name, version, "lib", file_path)
|
| |
|
| | if mode == "nv" and cur_name then
|
| | local cur_paths = get_deploy_paths(cur_name, cur_version, "lua", file_path:gsub("%.[^.]+$", ".lua"), repo)
|
| | table.insert(renames, { src = cur_paths.nv, dst = cur_paths.v })
|
| | cur_paths = get_deploy_paths(cur_name, cur_version, "lib", file_path, repo)
|
| | table.insert(renames, { src = cur_paths.nv, dst = cur_paths.v })
|
| | end
|
| | local backup = name ~= cur_name or version ~= cur_version
|
| | table.insert(installs, { fn = move_lib, src = source, dst = mode == "nv" and paths.nv or paths.v, backup = backup })
|
| | end)
|
| | end
|
| |
|
| | for _, op in ipairs(renames) do
|
| | op_rename(op)
|
| | end
|
| | for _, op in ipairs(installs) do
|
| | op_install(op)
|
| | end
|
| |
|
| | local writer = require("luarocks.manif.writer")
|
| | return writer.add_to_manifest(name, version, nil, deps_mode)
|
| | end
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | function repos.delete_version(name, version, deps_mode, quick)
|
| | assert(type(name) == "string" and not name:match("/"))
|
| | assert(type(version) == "string")
|
| | assert(type(deps_mode) == "string")
|
| |
|
| | local rock_manifest, load_err = manif.load_rock_manifest(name, version)
|
| | if not rock_manifest then return nil, load_err end
|
| |
|
| | local repo = cfg.root_dir
|
| | local renames = {}
|
| | local deletes = {}
|
| |
|
| | if rock_manifest.bin then
|
| | repos.recurse_rock_manifest_entry(rock_manifest.bin, function(file_path)
|
| | local paths = get_deploy_paths(name, version, "bin", file_path, repo)
|
| | local mode, cur_name, cur_version, item_name = check_spot_if_available(name, version, "bin", file_path)
|
| | if mode == "v" then
|
| | table.insert(deletes, { name = paths.v, suffix = cfg.wrapper_suffix })
|
| | else
|
| | table.insert(deletes, { name = paths.nv, suffix = cfg.wrapper_suffix })
|
| |
|
| | local next_name, next_version = manif.get_next_provider("command", item_name)
|
| | if next_name then
|
| | local next_paths = get_deploy_paths(next_name, next_version, "lua", file_path, repo)
|
| | table.insert(renames, { src = next_paths.v, dst = next_paths.nv, suffix = cfg.wrapper_suffix })
|
| | end
|
| | end
|
| | end)
|
| | end
|
| |
|
| | if rock_manifest.lua then
|
| | repos.recurse_rock_manifest_entry(rock_manifest.lua, function(file_path)
|
| | local paths = get_deploy_paths(name, version, "lua", file_path, repo)
|
| | local mode, cur_name, cur_version, item_name = check_spot_if_available(name, version, "lua", file_path)
|
| | if mode == "v" then
|
| | table.insert(deletes, { name = paths.v })
|
| | else
|
| | table.insert(deletes, { name = paths.nv })
|
| |
|
| | local next_name, next_version = manif.get_next_provider("module", item_name)
|
| | if next_name then
|
| | local next_lua_paths = get_deploy_paths(next_name, next_version, "lua", file_path, repo)
|
| | table.insert(renames, { src = next_lua_paths.v, dst = next_lua_paths.nv })
|
| | local next_lib_paths = get_deploy_paths(next_name, next_version, "lib", file_path:gsub("%.[^.]+$", ".lua"), repo)
|
| | table.insert(renames, { src = next_lib_paths.v, dst = next_lib_paths.nv })
|
| | end
|
| | end
|
| | end)
|
| | end
|
| |
|
| | if rock_manifest.lib then
|
| | repos.recurse_rock_manifest_entry(rock_manifest.lib, function(file_path)
|
| | local paths = get_deploy_paths(name, version, "lib", file_path, repo)
|
| | local mode, cur_name, cur_version, item_name = check_spot_if_available(name, version, "lib", file_path)
|
| | if mode == "v" then
|
| | table.insert(deletes, { name = paths.v })
|
| | else
|
| | table.insert(deletes, { name = paths.nv })
|
| |
|
| | local next_name, next_version = manif.get_next_provider("module", item_name)
|
| | if next_name then
|
| | local next_lua_paths = get_deploy_paths(next_name, next_version, "lua", file_path:gsub("%.[^.]+$", ".lua"), repo)
|
| | table.insert(renames, { src = next_lua_paths.v, dst = next_lua_paths.nv })
|
| | local next_lib_paths = get_deploy_paths(next_name, next_version, "lib", file_path, repo)
|
| | table.insert(renames, { src = next_lib_paths.v, dst = next_lib_paths.nv })
|
| | end
|
| | end
|
| | end)
|
| | end
|
| |
|
| | for _, op in ipairs(deletes) do
|
| | op_delete(op)
|
| | end
|
| | if not quick then
|
| | for _, op in ipairs(renames) do
|
| | op_rename(op)
|
| | end
|
| | end
|
| |
|
| | fs.delete(path.install_dir(name, version))
|
| | if not get_installed_versions(name) then
|
| | fs.delete(dir.path(cfg.rocks_dir, name))
|
| | end
|
| |
|
| | if quick then
|
| | return true
|
| | end
|
| |
|
| | local writer = require("luarocks.manif.writer")
|
| | return writer.remove_from_manifest(name, version, nil, deps_mode)
|
| | end
|
| |
|
| | return repos
|
| |
|