From e869c098d7432d039d3bdddd3f24ef9d20522a2f Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 23 Mar 2015 22:29:36 -0300 Subject: Fail nicely if CWD does not exist. Fixes #147. --- src/luarocks/command_line.lua | 6 +++++- src/luarocks/fs/unix/tools.lua | 6 ++++-- src/luarocks/fs/win32/tools.lua | 6 ++++-- test/testing.sh | 2 ++ 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua index a92a3f9d..96d7cb11 100644 --- a/src/luarocks/command_line.lua +++ b/src/luarocks/command_line.lua @@ -10,6 +10,7 @@ local cfg = require("luarocks.cfg") local path = require("luarocks.path") local dir = require("luarocks.dir") local deps = require("luarocks.deps") +local fs = require("luarocks.fs") local program = util.this_program("luarocks") @@ -79,7 +80,6 @@ function command_line.run_command(...) if flags["verbose"] then -- setting it in the config file will kick-in earlier in the process cfg.verbose = true - local fs = require("luarocks.fs") fs.verbose() end @@ -202,6 +202,10 @@ function command_line.run_command(...) end end + if not fs.exists(".") then + die("Current directory does not exist. Please run LuaRocks from an existing directory.") + end + if commands[command] then -- TODO the interface of run should be modified, to receive the -- flags table and the (possibly unpacked) nonflags arguments. diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua index 0823e74f..150a5ff8 100644 --- a/src/luarocks/fs/unix/tools.lua +++ b/src/luarocks/fs/unix/tools.lua @@ -21,7 +21,7 @@ end function tools.current_dir() local current = cfg.cache_pwd if not current then - local pipe = io.popen(fs.Q(vars.PWD)) + local pipe = io.popen(fs.Q(vars.PWD).." 2> /dev/null") current = pipe:read("*l") pipe:close() cfg.cache_pwd = current @@ -38,7 +38,9 @@ end -- @return boolean: true if command succeeds (status code 0), false -- otherwise. function tools.execute_string(cmd) - local code, err = os.execute(command_at(fs.current_dir(), cmd)) + local current = fs.current_dir() + if not current then return false end + local code, err = os.execute(command_at(current, cmd)) if code == 0 or code == true then return true else diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua index 8ea88f07..b9dce85c 100644 --- a/src/luarocks/fs/win32/tools.lua +++ b/src/luarocks/fs/win32/tools.lua @@ -39,7 +39,7 @@ end function tools.current_dir() local current = cfg.cache_pwd if not current then - local pipe = io.popen(fs.Q(vars.PWD)) + local pipe = io.popen(fs.Q(vars.PWD).. " 2> NUL") current = pipe:read("*l") pipe:close() cfg.cache_pwd = current @@ -56,7 +56,9 @@ end -- @return boolean: true if command succeeds (status code 0), false -- otherwise. function tools.execute_string(cmd) - cmd = command_at(fs.current_dir(), cmd) + local current = fs.current_dir() + if not current then return false end + cmd = command_at(current, cmd) local code = os.execute(cmd) if code == 0 or code == true then return true diff --git a/test/testing.sh b/test/testing.sh index b3c85191..becaa14f 100755 --- a/test/testing.sh +++ b/test/testing.sh @@ -346,6 +346,8 @@ fail_lint_invalid() { $luarocks lint invalid; } fail_show_invalid() { $luarocks show invalid; } fail_new_version_invalid() { $luarocks new_version invalid; } +fail_inexistent_dir() { mkdir idontexist; cd idontexist; rmdir ../idontexist; $luarocks; err=$?; cd ..; return $err; } + fail_make_norockspec() { $luarocks make; } fail_build_blank_arg() { $luarocks build --tree="" lpeg; } -- cgit v1.2.3-55-g6feb