diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2015-03-23 22:29:36 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2015-03-23 22:29:36 -0300 |
| commit | e869c098d7432d039d3bdddd3f24ef9d20522a2f (patch) | |
| tree | 83565496d4a3e7de62625945eb47eb1e5b0cb3c6 | |
| parent | 28ade76301133abc3b4ea96faefb51fe59f1c3ad (diff) | |
| download | luarocks-e869c098d7432d039d3bdddd3f24ef9d20522a2f.tar.gz luarocks-e869c098d7432d039d3bdddd3f24ef9d20522a2f.tar.bz2 luarocks-e869c098d7432d039d3bdddd3f24ef9d20522a2f.zip | |
Fail nicely if CWD does not exist. Fixes #147.
| -rw-r--r-- | src/luarocks/command_line.lua | 6 | ||||
| -rw-r--r-- | src/luarocks/fs/unix/tools.lua | 6 | ||||
| -rw-r--r-- | src/luarocks/fs/win32/tools.lua | 6 | ||||
| -rwxr-xr-x | 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") | |||
| 10 | local path = require("luarocks.path") | 10 | local path = require("luarocks.path") |
| 11 | local dir = require("luarocks.dir") | 11 | local dir = require("luarocks.dir") |
| 12 | local deps = require("luarocks.deps") | 12 | local deps = require("luarocks.deps") |
| 13 | local fs = require("luarocks.fs") | ||
| 13 | 14 | ||
| 14 | local program = util.this_program("luarocks") | 15 | local program = util.this_program("luarocks") |
| 15 | 16 | ||
| @@ -79,7 +80,6 @@ function command_line.run_command(...) | |||
| 79 | 80 | ||
| 80 | if flags["verbose"] then -- setting it in the config file will kick-in earlier in the process | 81 | if flags["verbose"] then -- setting it in the config file will kick-in earlier in the process |
| 81 | cfg.verbose = true | 82 | cfg.verbose = true |
| 82 | local fs = require("luarocks.fs") | ||
| 83 | fs.verbose() | 83 | fs.verbose() |
| 84 | end | 84 | end |
| 85 | 85 | ||
| @@ -202,6 +202,10 @@ function command_line.run_command(...) | |||
| 202 | end | 202 | end |
| 203 | end | 203 | end |
| 204 | 204 | ||
| 205 | if not fs.exists(".") then | ||
| 206 | die("Current directory does not exist. Please run LuaRocks from an existing directory.") | ||
| 207 | end | ||
| 208 | |||
| 205 | if commands[command] then | 209 | if commands[command] then |
| 206 | -- TODO the interface of run should be modified, to receive the | 210 | -- TODO the interface of run should be modified, to receive the |
| 207 | -- flags table and the (possibly unpacked) nonflags arguments. | 211 | -- 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 | |||
| 21 | function tools.current_dir() | 21 | function tools.current_dir() |
| 22 | local current = cfg.cache_pwd | 22 | local current = cfg.cache_pwd |
| 23 | if not current then | 23 | if not current then |
| 24 | local pipe = io.popen(fs.Q(vars.PWD)) | 24 | local pipe = io.popen(fs.Q(vars.PWD).." 2> /dev/null") |
| 25 | current = pipe:read("*l") | 25 | current = pipe:read("*l") |
| 26 | pipe:close() | 26 | pipe:close() |
| 27 | cfg.cache_pwd = current | 27 | cfg.cache_pwd = current |
| @@ -38,7 +38,9 @@ end | |||
| 38 | -- @return boolean: true if command succeeds (status code 0), false | 38 | -- @return boolean: true if command succeeds (status code 0), false |
| 39 | -- otherwise. | 39 | -- otherwise. |
| 40 | function tools.execute_string(cmd) | 40 | function tools.execute_string(cmd) |
| 41 | local code, err = os.execute(command_at(fs.current_dir(), cmd)) | 41 | local current = fs.current_dir() |
| 42 | if not current then return false end | ||
| 43 | local code, err = os.execute(command_at(current, cmd)) | ||
| 42 | if code == 0 or code == true then | 44 | if code == 0 or code == true then |
| 43 | return true | 45 | return true |
| 44 | else | 46 | 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 | |||
| 39 | function tools.current_dir() | 39 | function tools.current_dir() |
| 40 | local current = cfg.cache_pwd | 40 | local current = cfg.cache_pwd |
| 41 | if not current then | 41 | if not current then |
| 42 | local pipe = io.popen(fs.Q(vars.PWD)) | 42 | local pipe = io.popen(fs.Q(vars.PWD).. " 2> NUL") |
| 43 | current = pipe:read("*l") | 43 | current = pipe:read("*l") |
| 44 | pipe:close() | 44 | pipe:close() |
| 45 | cfg.cache_pwd = current | 45 | cfg.cache_pwd = current |
| @@ -56,7 +56,9 @@ end | |||
| 56 | -- @return boolean: true if command succeeds (status code 0), false | 56 | -- @return boolean: true if command succeeds (status code 0), false |
| 57 | -- otherwise. | 57 | -- otherwise. |
| 58 | function tools.execute_string(cmd) | 58 | function tools.execute_string(cmd) |
| 59 | cmd = command_at(fs.current_dir(), cmd) | 59 | local current = fs.current_dir() |
| 60 | if not current then return false end | ||
| 61 | cmd = command_at(current, cmd) | ||
| 60 | local code = os.execute(cmd) | 62 | local code = os.execute(cmd) |
| 61 | if code == 0 or code == true then | 63 | if code == 0 or code == true then |
| 62 | return true | 64 | 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; } | |||
| 346 | fail_show_invalid() { $luarocks show invalid; } | 346 | fail_show_invalid() { $luarocks show invalid; } |
| 347 | fail_new_version_invalid() { $luarocks new_version invalid; } | 347 | fail_new_version_invalid() { $luarocks new_version invalid; } |
| 348 | 348 | ||
| 349 | fail_inexistent_dir() { mkdir idontexist; cd idontexist; rmdir ../idontexist; $luarocks; err=$?; cd ..; return $err; } | ||
| 350 | |||
| 349 | fail_make_norockspec() { $luarocks make; } | 351 | fail_make_norockspec() { $luarocks make; } |
| 350 | 352 | ||
| 351 | fail_build_blank_arg() { $luarocks build --tree="" lpeg; } | 353 | fail_build_blank_arg() { $luarocks build --tree="" lpeg; } |
