diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2010-09-10 10:11:52 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2010-09-10 10:11:52 -0300 |
| commit | 6d83783e43061b6231f47dfb14eb6b5937555558 (patch) | |
| tree | cdc27779a6ad0a2dd8f703882aef77926c27ec82 /src | |
| parent | 5dcc8b797dad3a4a9b44e3101b06ee1306c81196 (diff) | |
| parent | 569ab48390725c2d87f9a89cdeb47bae3fc2cd46 (diff) | |
| download | luarocks-6d83783e43061b6231f47dfb14eb6b5937555558.tar.gz luarocks-6d83783e43061b6231f47dfb14eb6b5937555558.tar.bz2 luarocks-6d83783e43061b6231f47dfb14eb6b5937555558.zip | |
Merge branch 'master' of github.com:keplerproject/luarocks
Diffstat (limited to 'src')
| -rwxr-xr-x | src/bin/luarocks | 1 | ||||
| -rw-r--r-- | src/luarocks/build.lua | 14 | ||||
| -rw-r--r-- | src/luarocks/cfg.lua | 4 | ||||
| -rw-r--r-- | src/luarocks/command_line.lua | 72 | ||||
| -rw-r--r-- | src/luarocks/fs/lua.lua | 48 | ||||
| -rw-r--r-- | src/luarocks/fs/unix.lua | 1 | ||||
| -rw-r--r-- | src/luarocks/fs/unix/tools.lua | 9 | ||||
| -rw-r--r-- | src/luarocks/fs/win32.lua | 8 | ||||
| -rw-r--r-- | src/luarocks/help.lua | 1 | ||||
| -rw-r--r-- | src/luarocks/install.lua | 13 | ||||
| -rw-r--r-- | src/luarocks/make.lua | 6 | ||||
| -rw-r--r-- | src/luarocks/remove.lua | 7 | ||||
| -rw-r--r-- | src/luarocks/rep.lua | 6 | ||||
| -rw-r--r-- | src/luarocks/search.lua | 3 | ||||
| -rw-r--r-- | src/luarocks/show.lua | 136 | ||||
| -rw-r--r-- | src/luarocks/util.lua | 27 |
16 files changed, 271 insertions, 85 deletions
diff --git a/src/bin/luarocks b/src/bin/luarocks index fd0c1d9c..5da4bc25 100755 --- a/src/bin/luarocks +++ b/src/bin/luarocks | |||
| @@ -17,5 +17,6 @@ commands.remove = require("luarocks.remove") | |||
| 17 | commands.make = require("luarocks.make") | 17 | commands.make = require("luarocks.make") |
| 18 | commands.download = require("luarocks.download") | 18 | commands.download = require("luarocks.download") |
| 19 | commands.path = require("luarocks.path") | 19 | commands.path = require("luarocks.path") |
| 20 | commands.show = require("luarocks.show") | ||
| 20 | 21 | ||
| 21 | command_line.run_command(...) | 22 | command_line.run_command(...) |
diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index 62ac3808..b7386688 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua | |||
| @@ -11,6 +11,7 @@ local fs = require("luarocks.fs") | |||
| 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 manif = require("luarocks.manif") | 13 | local manif = require("luarocks.manif") |
| 14 | local cfg = require("luarocks.cfg") | ||
| 14 | 15 | ||
| 15 | help_summary = "Build/compile a rock." | 16 | help_summary = "Build/compile a rock." |
| 16 | help_arguments = "{<rockspec>|<rock>|<name> [<version>]}" | 17 | help_arguments = "{<rockspec>|<rock>|<name> [<version>]}" |
| @@ -229,6 +230,14 @@ function build_rockspec(rockspec_file, need_to_fetch, minimal_mode) | |||
| 229 | ok, err = manif.update_manifest(name, version) | 230 | ok, err = manif.update_manifest(name, version) |
| 230 | if err then return nil, err end | 231 | if err then return nil, err end |
| 231 | 232 | ||
| 233 | local license = "" | ||
| 234 | if rockspec.description.license then | ||
| 235 | license = ("(license: "..rockspec.description.license..")") | ||
| 236 | end | ||
| 237 | |||
| 238 | print() | ||
| 239 | print(name.." "..version.." is now built and installed in "..cfg.root_dir.." "..license) | ||
| 240 | |||
| 232 | util.remove_scheduled_function(rollback) | 241 | util.remove_scheduled_function(rollback) |
| 233 | return true | 242 | return true |
| 234 | end | 243 | end |
| @@ -269,6 +278,11 @@ function run(...) | |||
| 269 | end | 278 | end |
| 270 | assert(type(version) == "string" or not version) | 279 | assert(type(version) == "string" or not version) |
| 271 | 280 | ||
| 281 | if not flags["local"] and not fs.is_writable(cfg.root_dir) then | ||
| 282 | return nil, "Your user does not have write permissions in " .. cfg.root_dir .. | ||
| 283 | " \n-- you may want to run as a privileged user or use your local tree with --local." | ||
| 284 | end | ||
| 285 | |||
| 272 | if name:match("%.rockspec$") then | 286 | if name:match("%.rockspec$") then |
| 273 | return build_rockspec(name, true) | 287 | return build_rockspec(name, true) |
| 274 | elseif name:match("%.src%.rock$") then | 288 | elseif name:match("%.src%.rock$") then |
diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index 261411b7..45c73bf6 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua | |||
| @@ -63,9 +63,11 @@ end | |||
| 63 | if system == "FreeBSD" then | 63 | if system == "FreeBSD" then |
| 64 | detected.unix = true | 64 | detected.unix = true |
| 65 | detected.freebsd = true | 65 | detected.freebsd = true |
| 66 | detected.bsd = true | ||
| 66 | elseif system == "Darwin" then | 67 | elseif system == "Darwin" then |
| 67 | detected.unix = true | 68 | detected.unix = true |
| 68 | detected.macosx = true | 69 | detected.macosx = true |
| 70 | detected.bsd = true | ||
| 69 | elseif system == "Linux" then | 71 | elseif system == "Linux" then |
| 70 | detected.unix = true | 72 | detected.unix = true |
| 71 | detected.linux = true | 73 | detected.linux = true |
| @@ -83,7 +85,7 @@ end | |||
| 83 | 85 | ||
| 84 | -- Path configuration: | 86 | -- Path configuration: |
| 85 | 87 | ||
| 86 | local sys_config_file, home_config_file, home_tree | 88 | local sys_config_file, home_config_file |
| 87 | if detected.windows or detected.mingw32 then | 89 | if detected.windows or detected.mingw32 then |
| 88 | home = os.getenv("APPDATA") or "c:" | 90 | home = os.getenv("APPDATA") or "c:" |
| 89 | sys_config_file = "c:/luarocks/config.lua" | 91 | sys_config_file = "c:/luarocks/config.lua" |
diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua index d501d121..71ded87d 100644 --- a/src/luarocks/command_line.lua +++ b/src/luarocks/command_line.lua | |||
| @@ -33,6 +33,14 @@ local function is_writable(tree) | |||
| 33 | end | 33 | end |
| 34 | end | 34 | end |
| 35 | 35 | ||
| 36 | local function use_tree(tree) | ||
| 37 | cfg.root_dir = tree | ||
| 38 | cfg.rocks_dir = path.rocks_dir(tree) | ||
| 39 | cfg.deploy_bin_dir = path.deploy_bin_dir(tree) | ||
| 40 | cfg.deploy_lua_dir = path.deploy_lua_dir(tree) | ||
| 41 | cfg.deploy_lib_dir = path.deploy_lib_dir(tree) | ||
| 42 | end | ||
| 43 | |||
| 36 | --- Main command-line processor. | 44 | --- Main command-line processor. |
| 37 | -- Parses input arguments and calls the appropriate driver function | 45 | -- Parses input arguments and calls the appropriate driver function |
| 38 | -- to execute the action requested on the command-line, forwarding | 46 | -- to execute the action requested on the command-line, forwarding |
| @@ -58,30 +66,39 @@ function run_command(...) | |||
| 58 | local nonflags = { util.parse_flags(unpack(args)) } | 66 | local nonflags = { util.parse_flags(unpack(args)) } |
| 59 | local flags = table.remove(nonflags, 1) | 67 | local flags = table.remove(nonflags, 1) |
| 60 | cfg.flags = flags | 68 | cfg.flags = flags |
| 69 | |||
| 70 | local command | ||
| 71 | |||
| 72 | if flags["version"] then | ||
| 73 | print(program_name.." "..cfg.program_version) | ||
| 74 | print(program_description) | ||
| 75 | print() | ||
| 76 | os.exit(0) | ||
| 77 | elseif flags["help"] or #nonflags == 0 then | ||
| 78 | command = "help" | ||
| 79 | args = nonflags | ||
| 80 | else | ||
| 81 | command = nonflags[1] | ||
| 82 | for i, arg in ipairs(args) do | ||
| 83 | if arg == command then | ||
| 84 | table.remove(args, i) | ||
| 85 | break | ||
| 86 | end | ||
| 87 | end | ||
| 88 | end | ||
| 89 | command = command:gsub("-", "_") | ||
| 61 | 90 | ||
| 62 | if flags["to"] then | 91 | if flags["to"] then |
| 63 | if flags["to"] == true then | 92 | if flags["to"] == true then |
| 64 | die("Argument error: use --to=<path>") | 93 | die("Argument error: use --to=<path>") |
| 65 | end | 94 | end |
| 66 | local root_dir = fs.absolute_name(flags["to"]) | 95 | local root_dir = fs.absolute_name(flags["to"]) |
| 67 | cfg.root_dir = root_dir | 96 | use_tree(root_dir) |
| 68 | cfg.rocks_dir = path.rocks_dir(root_dir) | 97 | elseif flags["local"] then |
| 69 | cfg.deploy_bin_dir = path.deploy_bin_dir(root_dir) | 98 | use_tree(cfg.home_tree) |
| 70 | cfg.deploy_lua_dir = path.deploy_lua_dir(root_dir) | ||
| 71 | cfg.deploy_lib_dir = path.deploy_lib_dir(root_dir) | ||
| 72 | else | 99 | else |
| 73 | local trees = cfg.rocks_trees | 100 | local trees = cfg.rocks_trees |
| 74 | for i = #trees, 1, -1 do | 101 | use_tree(trees[#trees]) |
| 75 | local tree = trees[i] | ||
| 76 | if is_writable(tree) then | ||
| 77 | cfg.root_dir = tree | ||
| 78 | cfg.rocks_dir = path.rocks_dir(tree) | ||
| 79 | cfg.deploy_bin_dir = path.deploy_bin_dir(tree) | ||
| 80 | cfg.deploy_lua_dir = path.deploy_lua_dir(tree) | ||
| 81 | cfg.deploy_lib_dir = path.deploy_lib_dir(tree) | ||
| 82 | break | ||
| 83 | end | ||
| 84 | end | ||
| 85 | end | 102 | end |
| 86 | 103 | ||
| 87 | if type(cfg.root_dir) == "string" then | 104 | if type(cfg.root_dir) == "string" then |
| @@ -111,34 +128,13 @@ function run_command(...) | |||
| 111 | end | 128 | end |
| 112 | cfg.rocks_servers = { flags["only-from"] } | 129 | cfg.rocks_servers = { flags["only-from"] } |
| 113 | end | 130 | end |
| 114 | 131 | ||
| 115 | local command | ||
| 116 | |||
| 117 | if flags["version"] then | ||
| 118 | print(program_name.." "..cfg.program_version) | ||
| 119 | print(program_description) | ||
| 120 | print() | ||
| 121 | os.exit(0) | ||
| 122 | elseif flags["help"] or #nonflags == 0 then | ||
| 123 | command = "help" | ||
| 124 | args = nonflags | ||
| 125 | else | ||
| 126 | command = nonflags[1] | ||
| 127 | for i, arg in ipairs(args) do | ||
| 128 | if arg == command then | ||
| 129 | table.remove(args, i) | ||
| 130 | break | ||
| 131 | end | ||
| 132 | end | ||
| 133 | end | ||
| 134 | |||
| 135 | if command ~= "help" then | 132 | if command ~= "help" then |
| 136 | for k, v in pairs(cmdline_vars) do | 133 | for k, v in pairs(cmdline_vars) do |
| 137 | cfg.variables[k] = v | 134 | cfg.variables[k] = v |
| 138 | end | 135 | end |
| 139 | end | 136 | end |
| 140 | 137 | ||
| 141 | command = command:gsub("-", "_") | ||
| 142 | if commands[command] then | 138 | if commands[command] then |
| 143 | local xp, ok, err = xpcall(function() return commands[command].run(unpack(args)) end, function(err) | 139 | local xp, ok, err = xpcall(function() return commands[command].run(unpack(args)) end, function(err) |
| 144 | die(debug.traceback("LuaRocks "..cfg.program_version | 140 | die(debug.traceback("LuaRocks "..cfg.program_version |
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index f3d75b44..70df65be 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua | |||
| @@ -14,7 +14,6 @@ local _, ftp = pcall(require, "socket.ftp") | |||
| 14 | local zip_ok, lrzip = pcall(require, "luarocks.tools.zip") | 14 | local zip_ok, lrzip = pcall(require, "luarocks.tools.zip") |
| 15 | local unzip_ok, luazip = pcall(require, "zip"); _G.zip = nil | 15 | local unzip_ok, luazip = pcall(require, "zip"); _G.zip = nil |
| 16 | local lfs_ok, lfs = pcall(require, "lfs") | 16 | local lfs_ok, lfs = pcall(require, "lfs") |
| 17 | --local curl_ok, curl = pcall(require, "luacurl") | ||
| 18 | local md5_ok, md5 = pcall(require, "md5") | 17 | local md5_ok, md5 = pcall(require, "md5") |
| 19 | local posix_ok, posix = pcall(require, "posix") | 18 | local posix_ok, posix = pcall(require, "posix") |
| 20 | 19 | ||
| @@ -231,6 +230,7 @@ function copy(src, dest) | |||
| 231 | if destmode == "directory" then | 230 | if destmode == "directory" then |
| 232 | dest = dir.path(dest, dir.base_name(src)) | 231 | dest = dir.path(dest, dir.base_name(src)) |
| 233 | end | 232 | end |
| 233 | local perms = fs.get_permissions(src) | ||
| 234 | local src_h, err = io.open(src, "rb") | 234 | local src_h, err = io.open(src, "rb") |
| 235 | if not src_h then return nil, err end | 235 | if not src_h then return nil, err end |
| 236 | local dest_h, err = io.open(dest, "wb+") | 236 | local dest_h, err = io.open(dest, "wb+") |
| @@ -242,6 +242,7 @@ function copy(src, dest) | |||
| 242 | end | 242 | end |
| 243 | src_h:close() | 243 | src_h:close() |
| 244 | dest_h:close() | 244 | dest_h:close() |
| 245 | fs.chmod(dest, perms) | ||
| 245 | return true | 246 | return true |
| 246 | end | 247 | end |
| 247 | 248 | ||
| @@ -450,47 +451,6 @@ end | |||
| 450 | end | 451 | end |
| 451 | 452 | ||
| 452 | --------------------------------------------------------------------- | 453 | --------------------------------------------------------------------- |
| 453 | -- LuaCurl functions | ||
| 454 | --------------------------------------------------------------------- | ||
| 455 | |||
| 456 | if curl_ok then | ||
| 457 | |||
| 458 | --- Download a remote file. | ||
| 459 | -- @param url string: URL to be fetched. | ||
| 460 | -- @param filename string or nil: this function attempts to detect the | ||
| 461 | -- resulting local filename of the remote file as the basename of the URL; | ||
| 462 | -- if that is not correct (due to a redirection, for example), the local | ||
| 463 | -- filename can be given explicitly as this second argument. | ||
| 464 | -- @return boolean: true on success, false on failure. | ||
| 465 | function download(url, filename) | ||
| 466 | assert(type(url) == "string") | ||
| 467 | assert(type(filename) == "string" or not filename) | ||
| 468 | |||
| 469 | filename = dir.path(fs.current_dir(), filename or dir.base_name(url)) | ||
| 470 | |||
| 471 | local c = curl.new() | ||
| 472 | if not c then return false end | ||
| 473 | local file = io.open(filename, "wb") | ||
| 474 | if not file then return false end | ||
| 475 | local ok = c:setopt(curl.OPT_WRITEFUNCTION, function (stream, buffer) | ||
| 476 | stream:write(buffer) | ||
| 477 | return string.len(buffer) | ||
| 478 | end) | ||
| 479 | ok = ok and c:setopt(curl.OPT_WRITEDATA, file) | ||
| 480 | ok = ok and c:setopt(curl.OPT_BUFFERSIZE, 5000) | ||
| 481 | ok = ok and c:setopt(curl.OPT_HTTPHEADER, "Connection: Keep-Alive") | ||
| 482 | ok = ok and c:setopt(curl.OPT_URL, url) | ||
| 483 | ok = ok and c:setopt(curl.OPT_CONNECTTIMEOUT, 15) | ||
| 484 | ok = ok and c:setopt(curl.OPT_USERAGENT, cfg.user_agent) | ||
| 485 | ok = ok and c:perform() | ||
| 486 | ok = ok and c:close() | ||
| 487 | file:close() | ||
| 488 | return ok | ||
| 489 | end | ||
| 490 | |||
| 491 | end | ||
| 492 | |||
| 493 | --------------------------------------------------------------------- | ||
| 494 | -- LuaSocket functions | 454 | -- LuaSocket functions |
| 495 | --------------------------------------------------------------------- | 455 | --------------------------------------------------------------------- |
| 496 | 456 | ||
| @@ -613,6 +573,10 @@ function chmod(file, mode) | |||
| 613 | return err == 0 | 573 | return err == 0 |
| 614 | end | 574 | end |
| 615 | 575 | ||
| 576 | function get_permissions(file) | ||
| 577 | return posix.stat(file, "mode") | ||
| 578 | end | ||
| 579 | |||
| 616 | end | 580 | end |
| 617 | 581 | ||
| 618 | --------------------------------------------------------------------- | 582 | --------------------------------------------------------------------- |
diff --git a/src/luarocks/fs/unix.lua b/src/luarocks/fs/unix.lua index 94a3ad4e..f2290412 100644 --- a/src/luarocks/fs/unix.lua +++ b/src/luarocks/fs/unix.lua | |||
| @@ -122,4 +122,3 @@ end | |||
| 122 | function copy_binary(filename, dest) | 122 | function copy_binary(filename, dest) |
| 123 | return fs.copy(filename, dest) | 123 | return fs.copy(filename, dest) |
| 124 | end | 124 | end |
| 125 | |||
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua index 33dbc489..2bfa7c3e 100644 --- a/src/luarocks/fs/unix/tools.lua +++ b/src/luarocks/fs/unix/tools.lua | |||
| @@ -343,3 +343,12 @@ function unpack_archive(archive) | |||
| 343 | end | 343 | end |
| 344 | return true | 344 | return true |
| 345 | end | 345 | end |
| 346 | |||
| 347 | function get_permissions(filename) | ||
| 348 | local ret | ||
| 349 | local flag = cfg.is_platform("bsd") and "-f '%A'" or "-c '%a'" | ||
| 350 | local pipe = io.popen("stat "..flag.." "..fs.Q(filename)) | ||
| 351 | ret = pipe:read("*l") | ||
| 352 | pipe:close() | ||
| 353 | return ret | ||
| 354 | end | ||
diff --git a/src/luarocks/fs/win32.lua b/src/luarocks/fs/win32.lua index d87ad90d..44740850 100644 --- a/src/luarocks/fs/win32.lua +++ b/src/luarocks/fs/win32.lua | |||
| @@ -95,3 +95,11 @@ function copy_binary(filename, dest) | |||
| 95 | end | 95 | end |
| 96 | return true | 96 | return true |
| 97 | end | 97 | end |
| 98 | |||
| 99 | function chmod(filename, mode) | ||
| 100 | return true | ||
| 101 | end | ||
| 102 | |||
| 103 | function get_permissions(filename) | ||
| 104 | return "" | ||
| 105 | end | ||
diff --git a/src/luarocks/help.lua b/src/luarocks/help.lua index 04fea7ce..5162b917 100644 --- a/src/luarocks/help.lua +++ b/src/luarocks/help.lua | |||
| @@ -40,6 +40,7 @@ can be overriden with VAR=VALUE assignments. | |||
| 40 | --only-from=<server> Fetch rocks/rockspecs from this server only | 40 | --only-from=<server> Fetch rocks/rockspecs from this server only |
| 41 | (overrides any entries in the config file) | 41 | (overrides any entries in the config file) |
| 42 | --to=<tree> Which tree to operate on. | 42 | --to=<tree> Which tree to operate on. |
| 43 | --local Use the tree in the user's home directory. | ||
| 43 | 44 | ||
| 44 | Supported commands: | 45 | Supported commands: |
| 45 | ]]) | 46 | ]]) |
diff --git a/src/luarocks/install.lua b/src/luarocks/install.lua index 260c7751..4bb073dc 100644 --- a/src/luarocks/install.lua +++ b/src/luarocks/install.lua | |||
| @@ -79,6 +79,14 @@ function install_binary_rock(rock_file) | |||
| 79 | ok, err = manif.update_manifest(name, version) | 79 | ok, err = manif.update_manifest(name, version) |
| 80 | if err then return nil, err end | 80 | if err then return nil, err end |
| 81 | 81 | ||
| 82 | local license = "" | ||
| 83 | if rockspec.description.license then | ||
| 84 | license = ("(license: "..rockspec.description.license..")") | ||
| 85 | end | ||
| 86 | |||
| 87 | print() | ||
| 88 | print(name.." "..version.." is now installed in "..cfg.root_dir.." "..license) | ||
| 89 | |||
| 82 | util.remove_scheduled_function(rollback) | 90 | util.remove_scheduled_function(rollback) |
| 83 | return true | 91 | return true |
| 84 | end | 92 | end |
| @@ -99,6 +107,11 @@ function run(...) | |||
| 99 | return nil, "Argument missing, see help." | 107 | return nil, "Argument missing, see help." |
| 100 | end | 108 | end |
| 101 | 109 | ||
| 110 | if not flags["local"] and not fs.is_writable(cfg.root_dir) then | ||
| 111 | return nil, "Your user does not have write permissions in " .. cfg.root_dir .. | ||
| 112 | " \n-- you may want to run as a privileged user or use your local tree with --local." | ||
| 113 | end | ||
| 114 | |||
| 102 | if name:match("%.rockspec$") or name:match("%.src%.rock$") then | 115 | if name:match("%.rockspec$") or name:match("%.src%.rock$") then |
| 103 | local build = require("luarocks.build") | 116 | local build = require("luarocks.build") |
| 104 | return build.run(name) | 117 | return build.run(name) |
diff --git a/src/luarocks/make.lua b/src/luarocks/make.lua index cb2ba374..ec3772ac 100644 --- a/src/luarocks/make.lua +++ b/src/luarocks/make.lua | |||
| @@ -8,6 +8,7 @@ module("luarocks.make", package.seeall) | |||
| 8 | local build = require("luarocks.build") | 8 | local build = require("luarocks.build") |
| 9 | local fs = require("luarocks.fs") | 9 | local fs = require("luarocks.fs") |
| 10 | local util = require("luarocks.util") | 10 | local util = require("luarocks.util") |
| 11 | local cfg = require("luarocks.cfg") | ||
| 11 | 12 | ||
| 12 | help_summary = "Compile package in current directory using a rockspec." | 13 | help_summary = "Compile package in current directory using a rockspec." |
| 13 | help_arguments = "[<rockspec>]" | 14 | help_arguments = "[<rockspec>]" |
| @@ -30,6 +31,11 @@ To install rocks, you'll normally want to use the "install" and | |||
| 30 | function run(...) | 31 | function run(...) |
| 31 | local flags, rockspec = util.parse_flags(...) | 32 | local flags, rockspec = util.parse_flags(...) |
| 32 | assert(type(rockspec) == "string" or not rockspec) | 33 | assert(type(rockspec) == "string" or not rockspec) |
| 34 | |||
| 35 | if not flags["local"] and not fs.is_writable(cfg.root_dir) then | ||
| 36 | return nil, "Your user does not have write permissions in " .. cfg.root_dir .. | ||
| 37 | " \n-- you may want to run as a privileged user or use your local tree with --local." | ||
| 38 | end | ||
| 33 | 39 | ||
| 34 | if not rockspec then | 40 | if not rockspec then |
| 35 | local files = fs.list_dir(fs.current_dir()) | 41 | local files = fs.list_dir(fs.current_dir()) |
diff --git a/src/luarocks/remove.lua b/src/luarocks/remove.lua index afd299ae..d77f28fa 100644 --- a/src/luarocks/remove.lua +++ b/src/luarocks/remove.lua | |||
| @@ -11,6 +11,7 @@ local path = require("luarocks.path") | |||
| 11 | local util = require("luarocks.util") | 11 | local util = require("luarocks.util") |
| 12 | local cfg = require("luarocks.cfg") | 12 | local cfg = require("luarocks.cfg") |
| 13 | local manif = require("luarocks.manif") | 13 | local manif = require("luarocks.manif") |
| 14 | local fs = require("luarocks.fs") | ||
| 14 | 15 | ||
| 15 | help_summary = "Uninstall a rock." | 16 | help_summary = "Uninstall a rock." |
| 16 | help_arguments = "[--force] <name> [<version>]" | 17 | help_arguments = "[--force] <name> [<version>]" |
| @@ -81,6 +82,12 @@ function run(...) | |||
| 81 | if type(name) ~= "string" then | 82 | if type(name) ~= "string" then |
| 82 | return nil, "Argument missing, see help." | 83 | return nil, "Argument missing, see help." |
| 83 | end | 84 | end |
| 85 | |||
| 86 | if not flags["local"] and not fs.is_writable(cfg.rocks_dir) then | ||
| 87 | return nil, "Your user does not have write permissions in " .. cfg.rocks_dir .. | ||
| 88 | " \n-- you may want to run as a privileged user or use your local tree with --local." | ||
| 89 | end | ||
| 90 | |||
| 84 | local results = {} | 91 | local results = {} |
| 85 | search.manifest_search(results, cfg.rocks_dir, search.make_query(name, version)) | 92 | search.manifest_search(results, cfg.rocks_dir, search.make_query(name, version)) |
| 86 | 93 | ||
diff --git a/src/luarocks/rep.lua b/src/luarocks/rep.lua index 5da5953f..322ab166 100644 --- a/src/luarocks/rep.lua +++ b/src/luarocks/rep.lua | |||
| @@ -252,10 +252,11 @@ function delete_version(name, version) | |||
| 252 | local target = dir.path(deploy_dir, parent_path, file) | 252 | local target = dir.path(deploy_dir, parent_path, file) |
| 253 | local versioned = path.versioned_name(target, deploy_dir, name, version) | 253 | local versioned = path.versioned_name(target, deploy_dir, name, version) |
| 254 | if fs.exists(versioned) then | 254 | if fs.exists(versioned) then |
| 255 | fs.delete(versioned) | 255 | local ok = fs.delete(versioned) |
| 256 | fs.remove_dir_tree_if_empty(dir.dir_name(versioned)) | 256 | fs.remove_dir_tree_if_empty(dir.dir_name(versioned)) |
| 257 | if not ok then return nil, "Failed deleting "..versioned end | ||
| 257 | else | 258 | else |
| 258 | fs.delete(target) | 259 | local ok = fs.delete(target) |
| 259 | local next_name, next_version = manif.find_next_provider(target) | 260 | local next_name, next_version = manif.find_next_provider(target) |
| 260 | if next_name then | 261 | if next_name then |
| 261 | local versioned = path.versioned_name(target, deploy_dir, next_name, next_version) | 262 | local versioned = path.versioned_name(target, deploy_dir, next_name, next_version) |
| @@ -263,6 +264,7 @@ function delete_version(name, version) | |||
| 263 | fs.remove_dir_tree_if_empty(dir.dir_name(versioned)) | 264 | fs.remove_dir_tree_if_empty(dir.dir_name(versioned)) |
| 264 | end | 265 | end |
| 265 | fs.remove_dir_tree_if_empty(dir.dir_name(target)) | 266 | fs.remove_dir_tree_if_empty(dir.dir_name(target)) |
| 267 | if not ok then return nil, "Failed deleting "..target end | ||
| 266 | end | 268 | end |
| 267 | return true | 269 | return true |
| 268 | end | 270 | end |
diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua index 6303eb8c..97b86a45 100644 --- a/src/luarocks/search.lua +++ b/src/luarocks/search.lua | |||
| @@ -283,8 +283,9 @@ end | |||
| 283 | -- @param results table: A table where keys are package names and versions | 283 | -- @param results table: A table where keys are package names and versions |
| 284 | -- are tables matching version strings to an array of rocks servers. | 284 | -- are tables matching version strings to an array of rocks servers. |
| 285 | -- @param show_repo boolean or nil: Whether to show repository | 285 | -- @param show_repo boolean or nil: Whether to show repository |
| 286 | -- @param long boolean or nil: Whether to show module files | ||
| 286 | -- information or not. Default is true. | 287 | -- information or not. Default is true. |
| 287 | function print_results(results, show_repo) | 288 | function print_results(results, show_repo, long) |
| 288 | assert(type(results) == "table") | 289 | assert(type(results) == "table") |
| 289 | assert(type(show_repo) == "boolean" or not show_repo) | 290 | assert(type(show_repo) == "boolean" or not show_repo) |
| 290 | -- Force display of repo location for the time being | 291 | -- Force display of repo location for the time being |
diff --git a/src/luarocks/show.lua b/src/luarocks/show.lua new file mode 100644 index 00000000..fcdffb9c --- /dev/null +++ b/src/luarocks/show.lua | |||
| @@ -0,0 +1,136 @@ | |||
| 1 | |||
| 2 | --- Module implementing the LuaRocks "show" command. | ||
| 3 | -- Shows information about an installed rock. | ||
| 4 | module("luarocks.show", package.seeall) | ||
| 5 | |||
| 6 | local search = require("luarocks.search") | ||
| 7 | local cfg = require("luarocks.cfg") | ||
| 8 | local util = require("luarocks.util") | ||
| 9 | local path = require("luarocks.path") | ||
| 10 | local dir = require("luarocks.dir") | ||
| 11 | local deps = require("luarocks.deps") | ||
| 12 | local fetch = require("luarocks.fetch") | ||
| 13 | local manif = require("luarocks.manif") | ||
| 14 | help_summary = "Shows information about an installed rock." | ||
| 15 | |||
| 16 | help = [[ | ||
| 17 | <argument> is an existing package name. | ||
| 18 | Without any flags, show all module information. | ||
| 19 | With these flags, return only the desired information: | ||
| 20 | |||
| 21 | --home home page of project | ||
| 22 | --modules all modules provided by this package as used by require() | ||
| 23 | --deps packages this package depends on | ||
| 24 | --rockspec the full path of the rockspec file | ||
| 25 | --mversion the package version | ||
| 26 | --tree local tree where rock is installed | ||
| 27 | --rock-dir data directory of the installed rock | ||
| 28 | ]] | ||
| 29 | |||
| 30 | local function keys_as_string(t, sep) | ||
| 31 | return table.concat(util.keys(t), sep or " ") | ||
| 32 | end | ||
| 33 | |||
| 34 | local function word_wrap(line) | ||
| 35 | local width = tonumber(os.getenv("COLUMNS")) or 80 | ||
| 36 | if width > 80 then width = 80 end | ||
| 37 | if #line > width then | ||
| 38 | local brk = width | ||
| 39 | while brk > 0 and line:sub(brk, brk) ~= " " do | ||
| 40 | brk = brk - 1 | ||
| 41 | end | ||
| 42 | if brk > 0 then | ||
| 43 | return line:sub(1, brk-1) .. "\n" .. word_wrap(line:sub(brk+1)) | ||
| 44 | end | ||
| 45 | end | ||
| 46 | return line | ||
| 47 | end | ||
| 48 | |||
| 49 | local function format_text(text) | ||
| 50 | text = text:gsub("^%s*",""):gsub("%s$", ""):gsub("\n[ \t]+","\n"):gsub("([^\n])\n([^\n])","%1 %2") | ||
| 51 | local paragraphs = util.split_string(text, "\n\n") | ||
| 52 | for n, line in ipairs(paragraphs) do | ||
| 53 | paragraphs[n] = word_wrap(line) | ||
| 54 | end | ||
| 55 | return (table.concat(paragraphs, "\n\n"):gsub("%s$", "")) | ||
| 56 | end | ||
| 57 | |||
| 58 | --- Driver function for "show" command. | ||
| 59 | -- @param name or nil: an existing package name. | ||
| 60 | -- @param version string or nil: a version may also be passed. | ||
| 61 | -- @return boolean: True if succeeded, nil on errors. | ||
| 62 | function run(...) | ||
| 63 | local flags, name, version = util.parse_flags(...) | ||
| 64 | if not name then | ||
| 65 | return nil, "Argument missing, see help." | ||
| 66 | end | ||
| 67 | local results = {} | ||
| 68 | local query = search.make_query(name, version) | ||
| 69 | query.exact_name = true | ||
| 70 | local tree_map = {} | ||
| 71 | for _, tree in ipairs(cfg.rocks_trees) do | ||
| 72 | local rocks_dir = path.rocks_dir(tree) | ||
| 73 | tree_map[rocks_dir] = tree | ||
| 74 | search.manifest_search(results, rocks_dir, query) | ||
| 75 | end | ||
| 76 | |||
| 77 | if not next(results) then -- | ||
| 78 | return nil,"cannot find package "..name.."\nUse 'list' to find installed rocks" | ||
| 79 | end | ||
| 80 | |||
| 81 | local version,repo_url | ||
| 82 | local package, versions = util.sortedpairs(results)() | ||
| 83 | --question: what do we do about multiple versions? This should | ||
| 84 | --give us the latest version on the last repo (which is usually the global one) | ||
| 85 | for vs, repos in util.sortedpairs(versions, deps.compare_versions) do | ||
| 86 | version = vs | ||
| 87 | for _, rp in ipairs(repos) do repo_url = rp.repo end | ||
| 88 | end | ||
| 89 | |||
| 90 | |||
| 91 | local repo = tree_map[repo_url] | ||
| 92 | local directory = path.install_dir(name,version,repo) | ||
| 93 | local rockspec_file = path.rockspec_file(name, version, repo) | ||
| 94 | local rockspec, err = fetch.load_local_rockspec(rockspec_file) | ||
| 95 | if not rockspec then return nil,err end | ||
| 96 | |||
| 97 | local descript = rockspec.description | ||
| 98 | local manifest, err = manif.load_manifest(repo_url) | ||
| 99 | if not manifest then return nil,err end | ||
| 100 | local minfo = manifest.repository[name][version][1] | ||
| 101 | |||
| 102 | if flags["tree"] then print(repo) | ||
| 103 | elseif flags["rock-dir"] then print(directory) | ||
| 104 | elseif flags["home"] then print(descript.homepage) | ||
| 105 | elseif flags["modules"] then print(keys_as_string(minfo.modules)) | ||
| 106 | elseif flags["deps"] then print(keys_as_string(minfo.dependencies)) | ||
| 107 | elseif flags["rockspec"] then print(rockspec_file) | ||
| 108 | elseif flags["mversion"] then print(version) | ||
| 109 | else | ||
| 110 | print() | ||
| 111 | print(rockspec.package.." "..rockspec.version.." - "..descript.summary) | ||
| 112 | print() | ||
| 113 | print(format_text(descript.detailed)) | ||
| 114 | print() | ||
| 115 | if descript.license then | ||
| 116 | print("License: ", descript.license) | ||
| 117 | end | ||
| 118 | if descript.homepage then | ||
| 119 | print("Homepage: ", descript.homepage) | ||
| 120 | end | ||
| 121 | print("Installed in: ", repo) | ||
| 122 | if next(minfo.modules) then | ||
| 123 | print() | ||
| 124 | print("Modules:") | ||
| 125 | print("\t"..keys_as_string(minfo.modules, "\n\t")) | ||
| 126 | end | ||
| 127 | if next(minfo.dependencies) then | ||
| 128 | print() | ||
| 129 | print("Depends on:") | ||
| 130 | print("\t"..keys_as_string(minfo.dependencies, "\n\t")) | ||
| 131 | end | ||
| 132 | print() | ||
| 133 | end | ||
| 134 | return true | ||
| 135 | end | ||
| 136 | |||
diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index 164dd260..ed70b2ba 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua | |||
| @@ -243,6 +243,33 @@ function starts_with(s, prefix) | |||
| 243 | return s:sub(1,#prefix) == prefix | 243 | return s:sub(1,#prefix) == prefix |
| 244 | end | 244 | end |
| 245 | 245 | ||
| 246 | -- from http://lua-users.org/wiki/SplitJoin | ||
| 247 | -- by PhilippeLhoste | ||
| 248 | function split_string(str, delim, maxNb) | ||
| 249 | -- Eliminate bad cases... | ||
| 250 | if string.find(str, delim) == nil then | ||
| 251 | return { str } | ||
| 252 | end | ||
| 253 | if maxNb == nil or maxNb < 1 then | ||
| 254 | maxNb = 0 -- No limit | ||
| 255 | end | ||
| 256 | local result = {} | ||
| 257 | local pat = "(.-)" .. delim .. "()" | ||
| 258 | local nb = 0 | ||
| 259 | local lastPos | ||
| 260 | for part, pos in string.gfind(str, pat) do | ||
| 261 | nb = nb + 1 | ||
| 262 | result[nb] = part | ||
| 263 | lastPos = pos | ||
| 264 | if nb == maxNb then break end | ||
| 265 | end | ||
| 266 | -- Handle the last field | ||
| 267 | if nb ~= maxNb then | ||
| 268 | result[nb + 1] = string.sub(str, lastPos) | ||
| 269 | end | ||
| 270 | return result | ||
| 271 | end | ||
| 272 | |||
| 246 | --[[ | 273 | --[[ |
| 247 | Author: Julio Manuel Fernandez-Diaz | 274 | Author: Julio Manuel Fernandez-Diaz |
| 248 | Date: January 12, 2007 | 275 | Date: January 12, 2007 |
