From 2f67a04c91c5088d78d5f18013dded4f89382ff3 Mon Sep 17 00:00:00 2001 From: Hisham Date: Tue, 18 Oct 2016 17:59:19 -0400 Subject: Test case for issue #268 --- spec/install_spec.lua | 15 ++++++++++++++- test/test_environment.lua | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/spec/install_spec.lua b/spec/install_spec.lua index 8857e4bd..45b3e2f9 100644 --- a/spec/install_spec.lua +++ b/spec/install_spec.lua @@ -18,7 +18,9 @@ local extra_rocks = { "/lxsh-0.8.6-2.rockspec", "/say-1.2-1.src.rock", "/say-1.0-1.src.rock", - "/wsapi-1.6-1.src.rock" + "/wsapi-1.6-1.src.rock", + "/luafilesystem-1.6.3-2.src.rock", + "/luafilesystem-1.6.1-1.src.rock", } describe("LuaRocks install tests #blackbox #b_install", function() @@ -81,6 +83,17 @@ describe("LuaRocks install tests #blackbox #b_install", function() end assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luasec")) end) + + it('LuaRocks install - handle versioned modules when installing another version with --keep #268', function() + assert.is_true(run.luarocks_bool("install luafilesystem")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/lua/"..env_variables.LUA_VERSION.."/lfs."..test_env.lib_extension)) + assert.is_true(run.luarocks_bool("install luafilesystem 1.6.1 --keep")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/lua/"..env_variables.LUA_VERSION.."/lfs."..test_env.lib_extension)) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/lua/"..env_variables.LUA_VERSION.."/luafilesystem_1_6_1_1-lfs."..test_env.lib_extension)) + assert.is_true(run.luarocks_bool("install luafilesystem")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/lua/"..env_variables.LUA_VERSION.."/lfs."..test_env.lib_extension)) + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/lua/"..env_variables.LUA_VERSION.."/luafilesystem_1_6_1_1-lfs."..test_env.lib_extension)) + end) it("LuaRocks install only-deps of luasocket packed rock", function() assert.is_true(run.luarocks_bool("build --pack-binary-rock luasocket 3.0rc1-2")) diff --git a/test/test_environment.lua b/test/test_environment.lua index 87401a90..1d0b0c32 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -514,6 +514,7 @@ function test_env.setup_specs(extra_rocks) package.path = test_env.env_variables.LUA_PATH test_env.platform = execute_output(test_env.testing_paths.lua .. " -e \"print(require('luarocks.cfg').arch)\"", false, test_env.env_variables) + test_env.lib_extension = execute_output(test_env.testing_paths.lua .. " -e \"print(require('luarocks.cfg').lib_extension)\"", false, test_env.env_variables) test_env.md5sums = create_md5sums(test_env.testing_paths) test_env.setup_done = true title("RUNNING TESTS") -- cgit v1.2.3-55-g6feb From f83a936687d33b9b5ec9211d8b5534650b471385 Mon Sep 17 00:00:00 2001 From: Hisham Date: Tue, 18 Oct 2016 18:06:10 -0400 Subject: Regenerate manifest every time we delete a version. This is a naive implementation of the solution suggested by @mpeterv for #268. I'm merging this since it does produce more correct behavior, at the cost of a performance regression. We need a function akin to update_manifest for removing packages from a manifest. --- src/luarocks/build.lua | 4 ++-- src/luarocks/install.lua | 6 +++--- src/luarocks/manif.lua | 2 +- src/luarocks/purge.lua | 2 +- src/luarocks/remove.lua | 11 ++++++----- src/luarocks/repos.lua | 13 +++++++++++-- 6 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index f87b2f1b..f2784a3a 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua @@ -202,7 +202,7 @@ function build.build_rockspec(rockspec_file, need_to_fetch, minimal_mode, deps_m end if repos.is_installed(name, version) then - repos.delete_version(name, version) + repos.delete_version(name, version, deps_mode) end if not minimal_mode then @@ -325,7 +325,7 @@ function build.build_rockspec(rockspec_file, need_to_fetch, minimal_mode, deps_m util.remove_scheduled_function(rollback) rollback = util.schedule_function(function() - repos.delete_version(name, version) + repos.delete_version(name, version, deps_mode) end) ok, err = repos.run_hook(rockspec, "post_install") diff --git a/src/luarocks/install.lua b/src/luarocks/install.lua index acbf584a..daebfc70 100644 --- a/src/luarocks/install.lua +++ b/src/luarocks/install.lua @@ -50,7 +50,7 @@ function install.install_binary_rock(rock_file, deps_mode) return nil, "Incompatible architecture "..arch, "arch" end if repos.is_installed(name, version) then - repos.delete_version(name, version) + repos.delete_version(name, version, deps_mode) end local rollback = util.schedule_function(function() @@ -89,7 +89,7 @@ function install.install_binary_rock(rock_file, deps_mode) util.remove_scheduled_function(rollback) rollback = util.schedule_function(function() - repos.delete_version(name, version) + repos.delete_version(name, version, deps_mode) end) ok, err = repos.run_hook(rockspec, "post_install") @@ -168,7 +168,7 @@ function install.command(flags, name, version) ok, err = install.install_binary_rock(name, deps.get_deps_mode(flags)) end if not ok then return nil, err end - local name, version = ok, err + name, version = ok, err if (not flags["only-deps"]) and (not flags["keep"]) and not cfg.keep_other_versions then local ok, err = remove.remove_other_versions(name, version, flags["force"], flags["force-fast"]) if not ok then util.printerr(err) end diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua index 48b4f23d..a8bbf279 100644 --- a/src/luarocks/manif.lua +++ b/src/luarocks/manif.lua @@ -365,7 +365,7 @@ end -- @param deps_mode string: Dependency mode: "one" for the current default tree, -- "all" for all trees, "order" for all trees with priority >= the current default, -- "none" for the default dependency mode from the configuration. --- @param versioned boolean: if versioned versions of the manifest should be created. +-- @param remote boolean: 'true' if making a manifest for a rocks server. -- @return boolean or (nil, string): True if manifest was generated, -- or nil and an error message. function manif.make_manifest(repo, deps_mode, remote) diff --git a/src/luarocks/purge.lua b/src/luarocks/purge.lua index 1ce46c0f..17724e84 100644 --- a/src/luarocks/purge.lua +++ b/src/luarocks/purge.lua @@ -66,7 +66,7 @@ function purge.command(flags) break else util.printout("Removing "..package.." "..version.."...") - local ok, err = repos.delete_version(package, version, true) + local ok, err = repos.delete_version(package, version, "none", true) if not ok then util.printerr(err) end diff --git a/src/luarocks/remove.lua b/src/luarocks/remove.lua index d72fabaf..82c9818b 100644 --- a/src/luarocks/remove.lua +++ b/src/luarocks/remove.lua @@ -62,12 +62,15 @@ end --- Delete given versions of a program. -- @param name string: the name of a program -- @param versions array of string: the versions to be deleted. +-- @param deps_mode: string: Which trees to check dependencies for: +-- "one" for the current default tree, "all" for all trees, +-- "order" for all trees with priority >= the current default, "none" for no trees. -- @return boolean or (nil, string): true on success or nil and an error message. -local function delete_versions(name, versions) +local function delete_versions(name, versions, deps_mode) for version, _ in pairs(versions) do util.printout("Removing "..name.." "..version.."...") - local ok, err = repos.delete_version(name, version) + local ok, err = repos.delete_version(name, version, deps_mode) if not ok then return nil, err end end @@ -112,9 +115,7 @@ function remove.remove_search_results(results, name, deps_mode, force, fast) end end - local ok, err = delete_versions(name, versions) - if not ok then return nil, err end - ok, err = manif.make_manifest(cfg.rocks_dir, deps_mode) + local ok, err = delete_versions(name, versions, deps_mode) if not ok then return nil, err end util.printout("Removal successful.") diff --git a/src/luarocks/repos.lua b/src/luarocks/repos.lua index 86126a13..4e8a9a13 100644 --- a/src/luarocks/repos.lua +++ b/src/luarocks/repos.lua @@ -267,13 +267,17 @@ end -- Version numbers are compared as exact string comparison. -- @param name string: name of package -- @param version string: package version in string format +-- @param deps_mode: string: Which trees to check dependencies for: +-- "one" for the current default tree, "all" for all trees, +-- "order" for all trees with priority >= the current default, "none" for no trees. -- @param quick boolean: do not try to fix the versioned name -- of another version that provides the same module that -- was deleted. This is used during 'purge', as every module -- will be eventually deleted. -function repos.delete_version(name, version, quick) +function repos.delete_version(name, version, deps_mode, quick) assert(type(name) == "string") assert(type(version) == "string") + assert(type(deps_mode) == "string") local function delete_deployed_file_tree(file_tree, deploy_dir, suffix) return recurse_rock_manifest_tree(file_tree, @@ -323,7 +327,12 @@ function repos.delete_version(name, version, quick) if not get_installed_versions(name) then fs.delete(dir.path(cfg.rocks_dir, name)) end - return true + + if quick then + return true + end + + return manif.make_manifest(cfg.rocks_dir, deps_mode) end return repos -- cgit v1.2.3-55-g6feb