From 3a3f2cbaa50d353f4c26b39f59c015a20f28c4ae Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 18 Oct 2019 06:35:36 -0300 Subject: repos: rollback on installation failure (#1101) --- spec/install_spec.lua | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/install_spec.lua b/spec/install_spec.lua index 3b0b22fb..9b082ab8 100644 --- a/spec/install_spec.lua +++ b/spec/install_spec.lua @@ -81,7 +81,7 @@ describe("luarocks install #integration", function() assert.is_true(run.luarocks_bool("show luasocket")) end) - it("installs a package without its documentation #only", function() + it("installs a package without its documentation", function() assert.is_true(run.luarocks_bool("install wsapi 1.6 --no-doc")) assert.is_true(run.luarocks_bool("show wsapi 1.6")) assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/wsapi/1.6-1/doc")) @@ -195,6 +195,39 @@ describe("luarocks install #integration", function() assert.is_true(os.remove("luasocket-3.0rc1-2." .. test_env.platform .. ".rock")) end) + it("installation rolls back on failure", function() + assert.is_true(run.luarocks_bool("build --pack-binary-rock luasocket 3.0rc1-2")) + local luadir = testing_paths.testing_sys_tree .. "/share/lua/"..env_variables.LUA_VERSION + lfs.mkdir(luadir) + + run.luarocks_bool("remove " .. "luasocket") + + -- create a file where a folder should be + local fd = io.open(luadir .. "/socket", "w") + fd:write("\n") + fd:close() + + -- try to install and fail + assert.is_false(run.luarocks_bool("install " .. "luasocket-3.0rc1-2." .. test_env.platform .. ".rock")) + + -- file is still there + assert.is.truthy(lfs.attributes(luadir .. "/socket")) + -- no left overs from failed installation + assert.is.falsy(lfs.attributes(luadir .. "/mime.lua")) + + -- remove file + assert.is_true(os.remove(luadir .. "/socket")) + + -- try again and succeed + assert.is_true(run.luarocks_bool("install " .. "luasocket-3.0rc1-2." .. test_env.platform .. ".rock")) + + -- files installed successfully + assert.is.truthy(lfs.attributes(luadir .. "/socket/ftp.lua")) + assert.is.truthy(lfs.attributes(luadir .. "/mime.lua")) + + assert.is_true(os.remove("luasocket-3.0rc1-2." .. test_env.platform .. ".rock")) + end) + it("binary rock of cprint", function() assert.is_true(run.luarocks_bool("build --pack-binary-rock cprint")) assert.is_true(run.luarocks_bool("install cprint-0.1-2." .. test_env.platform .. ".rock")) -- cgit v1.2.3-55-g6feb