From 1a7f921e4cf1d4023340a8ba4dde17cb3e6bd311 Mon Sep 17 00:00:00 2001
From: Hisham Muhammad <hisham@gobolinux.org>
Date: Fri, 7 Feb 2020 10:42:50 +0100
Subject: fix downgrades of rocks containing directories (#1151)

Fixes #1141
---
 spec/build_spec.lua    |  8 ++++++++
 spec/test_spec.lua     | 18 ++++++------------
 src/luarocks/repos.lua |  6 +++---
 3 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/spec/build_spec.lua b/spec/build_spec.lua
index 14837d89..e498509f 100644
--- a/spec/build_spec.lua
+++ b/spec/build_spec.lua
@@ -25,6 +25,8 @@ local extra_rocks = {
    "/stdlib-41.0.0-1.src.rock",
    "/validate-args-1.5.4-1.rockspec",
    "spec/fixtures/a_rock-1.0-1.src.rock",
+   "/busted-2.0.0-1.rockspec",
+   "/busted-2.0.rc13-0.rockspec",
 }
 
 local c_module_source = [[
@@ -290,6 +292,12 @@ describe("LuaRocks build #integration", function()
          end)
       end
 
+      it("downgrades directories correctly", function()
+         assert(run.luarocks_bool("build --nodeps busted 2.0.0" ))
+         assert(run.luarocks_bool("build --nodeps busted 2.0.rc13" ))
+         assert(run.luarocks_bool("build --nodeps busted 2.0.0" ))
+      end)
+
       it("only deps", function()
          local rockspec = testing_paths.fixtures_dir .. "/build_only_deps-0.1-1.rockspec"
 
diff --git a/spec/test_spec.lua b/spec/test_spec.lua
index ca1d5917..ddb64b0e 100644
--- a/spec/test_spec.lua
+++ b/spec/test_spec.lua
@@ -8,13 +8,13 @@ local write_file = test_env.write_file
 test_env.unload_luarocks()
 
 local extra_rocks = {
-   "/busted-2.0.rc12-1.rockspec",
+   "/busted-2.0.0-1.rockspec",
    "/lua_cliargs-3.0-1.src.rock",
    "/luafilesystem-1.7.0-2.src.rock",
    "/luasystem-0.2.1-0.src.rock",
    "/dkjson-2.5-2.src.rock",
    "/say-1.3-1.rockspec",
-   "/luassert-1.7.10-0.rockspec",
+   "/luassert-1.8.0-0.rockspec",
    "/lua-term-0.7-1.rockspec",
    "/penlight-1.5.4-1.rockspec",
    "/mediator_lua-1.1.2-0.rockspec",   
@@ -40,16 +40,10 @@ describe("luarocks test #integration", function()
 
       lazy_setup(function()
          -- Try to cache rocks from the host system to speed up test
-         os.execute("luarocks pack busted")
-         os.execute("luarocks pack lua_cliargs")
-         os.execute("luarocks pack luafilesystem")
-         os.execute("luarocks pack dkjson")
-         os.execute("luarocks pack luasystem")
-         os.execute("luarocks pack say")
-         os.execute("luarocks pack luassert")
-         os.execute("luarocks pack lua-term")
-         os.execute("luarocks pack penlight")
-         os.execute("luarocks pack mediator_lua")
+         for _, r in ipairs(extra_rocks) do
+            local n, v = r:match("^/(.*)%-([^%-]+)%-%d+%.[^%-]+$")
+            os.execute("luarocks pack " .. n .. " " .. v)
+         end
          if test_env.TEST_TARGET_OS == "windows" then
             os.execute("move *.rock " .. testing_paths.testing_server)
          else
diff --git a/src/luarocks/repos.lua b/src/luarocks/repos.lua
index e9dddc7c..b2a7d81a 100644
--- a/src/luarocks/repos.lua
+++ b/src/luarocks/repos.lua
@@ -272,7 +272,7 @@ local function backup_existing(should_backup, target)
       until not fs.exists(backup) -- Slight race condition here, but shouldn't be a problem.
    
       util.warning(target.." is not tracked by this installation of LuaRocks. Moving it to "..backup)
-      local move_ok, move_err = fs.move(target, backup)
+      local move_ok, move_err = os.rename(target, backup)
       if not move_ok then
          return nil, move_err
       end
@@ -331,7 +331,7 @@ end
 local function rollback_install(op)
    fs.delete(op.dst)
    if op.backup_file then
-      fs.move(op.backup_file, op.dst)
+      os.rename(op.backup_file, op.dst)
    end
    fs.remove_dir_tree_if_empty(dir.dir_name(op.dst))
    return true
@@ -347,7 +347,7 @@ local function op_rename(op)
    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)
+      local ok, err = os.rename(op.src, op.dst)
       fs.remove_dir_tree_if_empty(dir.dir_name(op.src))
       return ok, err
    else
-- 
cgit v1.2.3-55-g6feb