aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--spec/quick/build.q35
-rw-r--r--src/luarocks/cmd.lua13
-rw-r--r--src/luarocks/fs/unix/tools.lua5
3 files changed, 40 insertions, 13 deletions
diff --git a/spec/quick/build.q b/spec/quick/build.q
index ee519adf..55bb7519 100644
--- a/spec/quick/build.q
+++ b/spec/quick/build.q
@@ -83,8 +83,15 @@ RUN: luarocks build --tree=/usr ./a_rock-1.0.1-rockspec
83EXIT: 4 83EXIT: 4
84STDERR: 84STDERR:
85-------------------------------------------------------------------------------- 85--------------------------------------------------------------------------------
86requires exclusive access 86requires exclusive write access
87use --force-lock 87--------------------------------------------------------------------------------
88
89We show the OS permission denied error, so we don't show the --force-lock
90message.
91
92NOT_STDERR:
93--------------------------------------------------------------------------------
94try --force-lock
88-------------------------------------------------------------------------------- 95--------------------------------------------------------------------------------
89 96
90NOT_EXISTS: %{testing_sys_rocks}/a_rock/1.0-1/a_rock-1.0-1.rockspec 97NOT_EXISTS: %{testing_sys_rocks}/a_rock/1.0-1/a_rock-1.0-1.rockspec
@@ -93,8 +100,15 @@ RUN: luarocks build --tree=/usr ./a_rock-1.0.1-rockspec --force-lock
93EXIT: 4 100EXIT: 4
94STDERR: 101STDERR:
95-------------------------------------------------------------------------------- 102--------------------------------------------------------------------------------
96requires exclusive access 103requires exclusive write access
97failed to force the lock 104--------------------------------------------------------------------------------
105
106We show the OS permission denied error, so we don't show the --force-lock
107message.
108
109NOT_STDERR:
110--------------------------------------------------------------------------------
111try --force-lock
98-------------------------------------------------------------------------------- 112--------------------------------------------------------------------------------
99 113
100NOT_EXISTS: %{testing_sys_rocks}/a_rock/1.0-1/a_rock-1.0-1.rockspec 114NOT_EXISTS: %{testing_sys_rocks}/a_rock/1.0-1/a_rock-1.0-1.rockspec
@@ -108,8 +122,15 @@ RUN: luarocks build --tree=/usr/invalid ./a_rock-1.0.1-rockspec
108EXIT: 4 122EXIT: 4
109STDERR: 123STDERR:
110-------------------------------------------------------------------------------- 124--------------------------------------------------------------------------------
111requires exclusive access 125requires exclusive write access
112use --force-lock 126--------------------------------------------------------------------------------
127
128We show the OS permission denied error, so we don't show the --force-lock
129message.
130
131NOT_STDERR:
132--------------------------------------------------------------------------------
133try --force-lock
113-------------------------------------------------------------------------------- 134--------------------------------------------------------------------------------
114 135
115NOT_EXISTS: %{testing_sys_rocks}/a_rock/1.0-1/a_rock-1.0-1.rockspec 136NOT_EXISTS: %{testing_sys_rocks}/a_rock/1.0-1/a_rock-1.0-1.rockspec
@@ -118,7 +139,7 @@ RUN: luarocks build --tree=/usr/invalid ./a_rock-1.0.1-rockspec --force-lock
118EXIT: 4 139EXIT: 4
119STDERR: 140STDERR:
120-------------------------------------------------------------------------------- 141--------------------------------------------------------------------------------
121requires exclusive access 142requires exclusive write access
122failed to force the lock 143failed to force the lock
123-------------------------------------------------------------------------------- 144--------------------------------------------------------------------------------
124 145
diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua
index ca22c0db..b6d0d47e 100644
--- a/src/luarocks/cmd.lua
+++ b/src/luarocks/cmd.lua
@@ -732,12 +732,15 @@ function cmd.run_command(description, commands, external_namespace, ...)
732 if cmd_mod.needs_lock and cmd_mod.needs_lock(args) then 732 if cmd_mod.needs_lock and cmd_mod.needs_lock(args) then
733 lock, err = fs.lock_access(path.root_dir(cfg.root_dir), args.force_lock) 733 lock, err = fs.lock_access(path.root_dir(cfg.root_dir), args.force_lock)
734 if not lock then 734 if not lock then
735 local try_force = args.force_lock 735 err = args.force_lock
736 and (" - failed to force the lock" .. (err and ": " .. err or "")) 736 and ("failed to force the lock" .. (err and ": " .. err or ""))
737 or " - use --force-lock to overwrite the lock" 737 or (err and err ~= "File exists")
738 and err
739 or "try --force-lock to overwrite the lock"
740
738 die("command '" .. args.command .. "' " .. 741 die("command '" .. args.command .. "' " ..
739 "requires exclusive access to " .. path.root_dir(cfg.root_dir) .. 742 "requires exclusive write access to " .. path.root_dir(cfg.root_dir) .. " - " ..
740 try_force, cmd.errorcodes.LOCK) 743 err, cmd.errorcodes.LOCK)
741 end 744 end
742 end 745 end
743 746
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua
index efd4d624..a0fba784 100644
--- a/src/luarocks/fs/unix/tools.lua
+++ b/src/luarocks/fs/unix/tools.lua
@@ -319,7 +319,10 @@ function tools.is_superuser()
319end 319end
320 320
321function tools.lock_access(dirname, force) 321function tools.lock_access(dirname, force)
322 fs.make_dir(dirname) 322 local ok, err = fs.make_dir(dirname)
323 if not ok then
324 return nil, err
325 end
323 326
324 local tempfile = dir.path(dirname, ".lock.tmp." .. tostring(math.random(100000000))) 327 local tempfile = dir.path(dirname, ".lock.tmp." .. tostring(math.random(100000000)))
325 328