diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/luarocks/build.lua | 5 | ||||
-rw-r--r-- | src/luarocks/build/builtin.lua | 2 | ||||
-rw-r--r-- | src/luarocks/cfg.lua | 19 | ||||
-rw-r--r-- | src/luarocks/download.lua | 5 | ||||
-rw-r--r-- | src/luarocks/fs/lua.lua | 19 | ||||
-rw-r--r-- | src/luarocks/fs/unix.lua | 34 | ||||
-rw-r--r-- | src/luarocks/fs/unix/tools.lua | 2 | ||||
-rw-r--r-- | src/luarocks/help.lua | 72 | ||||
-rw-r--r-- | src/luarocks/make.lua | 5 | ||||
-rw-r--r-- | src/luarocks/persist.lua | 10 |
10 files changed, 99 insertions, 74 deletions
diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index fb9e4a4f..9a67f00b 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua | |||
@@ -314,12 +314,11 @@ function run(...) | |||
314 | end | 314 | end |
315 | assert(type(version) == "string" or not version) | 315 | assert(type(version) == "string" or not version) |
316 | 316 | ||
317 | local ok, err = fs.check_command_permissions(flags) | ||
318 | if not ok then return nil, err end | ||
319 | |||
320 | if flags["pack-binary-rock"] then | 317 | if flags["pack-binary-rock"] then |
321 | return pack.pack_binary_rock(name, version, do_build, name, version) | 318 | return pack.pack_binary_rock(name, version, do_build, name, version) |
322 | else | 319 | else |
320 | local ok, err = fs.check_command_permissions(flags) | ||
321 | if not ok then return nil, err end | ||
323 | return do_build(name, version) | 322 | return do_build(name, version) |
324 | end | 323 | end |
325 | end | 324 | end |
diff --git a/src/luarocks/build/builtin.lua b/src/luarocks/build/builtin.lua index 2a18286f..c2bb0106 100644 --- a/src/luarocks/build/builtin.lua +++ b/src/luarocks/build/builtin.lua | |||
@@ -187,7 +187,7 @@ function run(rockspec) | |||
187 | if type(info) == "string" then | 187 | if type(info) == "string" then |
188 | local ext = info:match(".([^.]+)$") | 188 | local ext = info:match(".([^.]+)$") |
189 | if ext == "lua" then | 189 | if ext == "lua" then |
190 | if info:match("init.lua$") then | 190 | if info:match("init%.lua$") and not name:match("%.init$") then |
191 | moddir = path.module_to_path(name..".init") | 191 | moddir = path.module_to_path(name..".init") |
192 | end | 192 | end |
193 | local dest = dir.path(luadir, moddir) | 193 | local dest = dir.path(luadir, moddir) |
diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index ec019761..9fce84f8 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua | |||
@@ -25,7 +25,7 @@ end | |||
25 | 25 | ||
26 | _M.site_config = site_config | 26 | _M.site_config = site_config |
27 | 27 | ||
28 | program_version = "2.0.7" | 28 | program_version = "2.0.7.1" |
29 | user_agent = "LuaRocks/"..program_version | 29 | user_agent = "LuaRocks/"..program_version |
30 | 30 | ||
31 | local persist = require("luarocks.persist") | 31 | local persist = require("luarocks.persist") |
@@ -91,6 +91,7 @@ end | |||
91 | -- Path configuration: | 91 | -- Path configuration: |
92 | 92 | ||
93 | local sys_config_file, home_config_file | 93 | local sys_config_file, home_config_file |
94 | local sys_config_ok, home_config_ok = false, false | ||
94 | if detected.windows or detected.mingw32 then | 95 | if detected.windows or detected.mingw32 then |
95 | home = os.getenv("APPDATA") or "c:" | 96 | home = os.getenv("APPDATA") or "c:" |
96 | sys_config_file = "c:/luarocks/config.lua" | 97 | sys_config_file = "c:/luarocks/config.lua" |
@@ -106,12 +107,18 @@ end | |||
106 | variables = {} | 107 | variables = {} |
107 | rocks_trees = {} | 108 | rocks_trees = {} |
108 | 109 | ||
109 | persist.load_into_table(site_config.LUAROCKS_SYSCONFIG or sys_config_file, _M) | 110 | local ok, err = persist.load_into_table(site_config.LUAROCKS_SYSCONFIG or sys_config_file, _M) |
111 | if ok then | ||
112 | sys_config_ok = true | ||
113 | elseif err and ok == nil then | ||
114 | io.stderr:write(err.."\n") | ||
115 | end | ||
110 | 116 | ||
111 | if not site_config.LUAROCKS_FORCE_CONFIG then | 117 | if not site_config.LUAROCKS_FORCE_CONFIG then |
112 | home_config_file = os.getenv("LUAROCKS_CONFIG") or home_config_file | 118 | home_config_file = os.getenv("LUAROCKS_CONFIG") or home_config_file |
113 | local home_overrides = persist.load_into_table(home_config_file, { home = home }) | 119 | local home_overrides, err = persist.load_into_table(home_config_file, { home = home }) |
114 | if home_overrides then | 120 | if home_overrides then |
121 | home_config_ok = true | ||
115 | local util = require("luarocks.util") | 122 | local util = require("luarocks.util") |
116 | if home_overrides.rocks_trees then | 123 | if home_overrides.rocks_trees then |
117 | _M.rocks_trees = nil | 124 | _M.rocks_trees = nil |
@@ -120,6 +127,8 @@ if not site_config.LUAROCKS_FORCE_CONFIG then | |||
120 | _M.rocks_servers = nil | 127 | _M.rocks_servers = nil |
121 | end | 128 | end |
122 | util.deep_merge(_M, home_overrides) | 129 | util.deep_merge(_M, home_overrides) |
130 | elseif err and home_overrides == nil then | ||
131 | io.stderr:write(err.."\n") | ||
123 | end | 132 | end |
124 | end | 133 | end |
125 | 134 | ||
@@ -404,6 +413,10 @@ for _,tree in ipairs(rocks_trees) do | |||
404 | end | 413 | end |
405 | end | 414 | end |
406 | 415 | ||
416 | function which_config() | ||
417 | return sys_config_file, sys_config_ok, home_config_file, home_config_ok | ||
418 | end | ||
419 | |||
407 | --- Check if platform was detected | 420 | --- Check if platform was detected |
408 | -- @param query string: The platform name to check. | 421 | -- @param query string: The platform name to check. |
409 | -- @return boolean: true if LuaRocks is currently running on queried platform. | 422 | -- @return boolean: true if LuaRocks is currently running on queried platform. |
diff --git a/src/luarocks/download.lua b/src/luarocks/download.lua index 6ae5f7af..268dc113 100644 --- a/src/luarocks/download.lua +++ b/src/luarocks/download.lua | |||
@@ -9,11 +9,12 @@ local fetch = require("luarocks.fetch") | |||
9 | local search = require("luarocks.search") | 9 | local search = require("luarocks.search") |
10 | 10 | ||
11 | help_summary = "Download a specific rock file from a rocks server." | 11 | help_summary = "Download a specific rock file from a rocks server." |
12 | help_arguments = "[--all] [--source] [--arch=<arch>] [<name> [<version>]]" | 12 | help_arguments = "[--all] [--arch=<arch> | --source | --rockspec] [<name> [<version>]]" |
13 | 13 | ||
14 | help = [[ | 14 | help = [[ |
15 | --all Download multiple rock files if there is more than one match. | 15 | --all Download all files if there are multiple matches. |
16 | --source Download .src.rock if available. | 16 | --source Download .src.rock if available. |
17 | --rockspec Download .rockspec if available. | ||
17 | --arch=<arch> Download rock for a specific architecture. | 18 | --arch=<arch> Download rock for a specific architecture. |
18 | ]] | 19 | ]] |
19 | 20 | ||
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index d75bb476..1cae25f4 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua | |||
@@ -578,7 +578,26 @@ end | |||
578 | 578 | ||
579 | if posix_ok then | 579 | if posix_ok then |
580 | 580 | ||
581 | local octal_to_rwx = { | ||
582 | ["0"] = "---", | ||
583 | ["1"] = "--x", | ||
584 | ["2"] = "-w-", | ||
585 | ["3"] = "-wx", | ||
586 | ["4"] = "r--", | ||
587 | ["5"] = "r-x", | ||
588 | ["6"] = "rw-", | ||
589 | ["7"] = "rwx", | ||
590 | } | ||
591 | |||
581 | function chmod(file, mode) | 592 | function chmod(file, mode) |
593 | -- LuaPosix (as of 5.1.15) does not support octal notation... | ||
594 | if mode:sub(1,1) == "0" then | ||
595 | local new_mode = {} | ||
596 | for c in mode:sub(2):gmatch(".") do | ||
597 | table.insert(new_mode, octal_to_rwx[c]) | ||
598 | end | ||
599 | mode = table.concat(new_mode) | ||
600 | end | ||
582 | local err = posix.chmod(file, mode) | 601 | local err = posix.chmod(file, mode) |
583 | return err == 0 | 602 | return err == 0 |
584 | end | 603 | end |
diff --git a/src/luarocks/fs/unix.lua b/src/luarocks/fs/unix.lua index 262cb3d0..979fd166 100644 --- a/src/luarocks/fs/unix.lua +++ b/src/luarocks/fs/unix.lua | |||
@@ -54,7 +54,7 @@ function wrap_script(file, dest) | |||
54 | wrapper:write('export LUA_PATH LUA_CPATH\n') | 54 | wrapper:write('export LUA_PATH LUA_CPATH\n') |
55 | wrapper:write('exec "'..dir.path(cfg.variables["LUA_BINDIR"], cfg.lua_interpreter)..'" -lluarocks.loader "'..file..'" "$@"\n') | 55 | wrapper:write('exec "'..dir.path(cfg.variables["LUA_BINDIR"], cfg.lua_interpreter)..'" -lluarocks.loader "'..file..'" "$@"\n') |
56 | wrapper:close() | 56 | wrapper:close() |
57 | if fs.execute("chmod +x",wrapname) then | 57 | if fs.chmod(wrapname, "0755") then |
58 | return true | 58 | return true |
59 | else | 59 | else |
60 | return nil, "Could not make "..wrapname.." executable." | 60 | return nil, "Could not make "..wrapname.." executable." |
@@ -74,35 +74,6 @@ function is_actual_binary(filename) | |||
74 | if file then | 74 | if file then |
75 | local found = false | 75 | local found = false |
76 | local first = file:read() | 76 | local first = file:read() |
77 | if first:match("#!.*lua") then | ||
78 | found = true | ||
79 | elseif first:match("#!/bin/sh") then | ||
80 | local line = file:read() | ||
81 | line = file:read() | ||
82 | if not(line and line:match("LUA_PATH")) then | ||
83 | found = true | ||
84 | end | ||
85 | end | ||
86 | file:close() | ||
87 | if found then | ||
88 | return false | ||
89 | else | ||
90 | return true | ||
91 | end | ||
92 | else | ||
93 | return true | ||
94 | end | ||
95 | return false | ||
96 | end | ||
97 | |||
98 | function is_actual_binary(filename) | ||
99 | if filename:match("%.lua$") then | ||
100 | return false | ||
101 | end | ||
102 | local file = io.open(filename) | ||
103 | if file then | ||
104 | local found = false | ||
105 | local first = file:read() | ||
106 | if not first then | 77 | if not first then |
107 | file:close() | 78 | file:close() |
108 | util.printerr("Warning: could not read "..filename) | 79 | util.printerr("Warning: could not read "..filename) |
@@ -127,6 +98,5 @@ function is_actual_binary(filename) | |||
127 | end | 98 | end |
128 | 99 | ||
129 | function copy_binary(filename, dest) | 100 | function copy_binary(filename, dest) |
130 | -- LuaPosix (as of 5.1.15) does not support octal notation... | 101 | return fs.copy(filename, dest, "0755") |
131 | return fs.copy(filename, dest, "u=rwx,g=rx,o=rx") | ||
132 | end | 102 | end |
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua index 5e91439b..d6d60adc 100644 --- a/src/luarocks/fs/unix/tools.lua +++ b/src/luarocks/fs/unix/tools.lua | |||
@@ -101,7 +101,7 @@ function copy(src, dest, perm) | |||
101 | if fs.is_dir(dest) then | 101 | if fs.is_dir(dest) then |
102 | dest = dir.path(dest, dir.base_name(src)) | 102 | dest = dir.path(dest, dir.base_name(src)) |
103 | end | 103 | end |
104 | if fs.execute(vars.CHMOD, perm, dest) then | 104 | if fs.chmod(dest, perm) then |
105 | return true | 105 | return true |
106 | else | 106 | else |
107 | return false, "Failed setting permissions of "..dest | 107 | return false, "Failed setting permissions of "..dest |
diff --git a/src/luarocks/help.lua b/src/luarocks/help.lua index 718580ce..3a366f44 100644 --- a/src/luarocks/help.lua +++ b/src/luarocks/help.lua | |||
@@ -9,13 +9,21 @@ module("luarocks.help", package.seeall) | |||
9 | local util = require("luarocks.util") | 9 | local util = require("luarocks.util") |
10 | local cfg = require("luarocks.cfg") | 10 | local cfg = require("luarocks.cfg") |
11 | 11 | ||
12 | help_summary = "Help on commands." | 12 | help_summary = "Help on commands. Type '"..program_name.." help <command>' for more." |
13 | 13 | ||
14 | help_arguments = "[<command>]" | 14 | help_arguments = "[<command>]" |
15 | help = [[ | 15 | help = [[ |
16 | <command> is the command to show help for. | 16 | <command> is the command to show help for. |
17 | ]] | 17 | ]] |
18 | 18 | ||
19 | local function print_banner() | ||
20 | util.printout("\nLuaRocks "..cfg.program_version..", a module deployment system for Lua") | ||
21 | end | ||
22 | |||
23 | local function print_section(section) | ||
24 | util.printout("\n"..section) | ||
25 | end | ||
26 | |||
19 | --- Driver function for the "help" command. | 27 | --- Driver function for the "help" command. |
20 | -- @param command string or nil: command to show help for; if not | 28 | -- @param command string or nil: command to show help for; if not |
21 | -- given, help summaries for all commands are shown. | 29 | -- given, help summaries for all commands are shown. |
@@ -25,27 +33,29 @@ function run(...) | |||
25 | local flags, command = util.parse_flags(...) | 33 | local flags, command = util.parse_flags(...) |
26 | 34 | ||
27 | if not command then | 35 | if not command then |
36 | local sys_file, sys_ok, home_file, home_ok = cfg.which_config() | ||
37 | print_banner() | ||
38 | print_section("NAME") | ||
39 | util.printout("\t"..program_name..[[ - ]]..program_description) | ||
40 | print_section("SYNOPSIS") | ||
41 | util.printout("\t"..program_name..[[ [--from=<server> | --only-from=<server>] [--to=<tree>] [VAR=VALUE]... <command> [<argument>] ]]) | ||
42 | print_section("GENERAL OPTIONS") | ||
28 | util.printout([[ | 43 | util.printout([[ |
29 | LuaRocks ]]..cfg.program_version..[[, a module deployment system for Lua | 44 | These apply to all commands, as appropriate: |
30 | |||
31 | ]]..program_name..[[ - ]]..program_description..[[ | ||
32 | 45 | ||
33 | usage: ]]..program_name..[[ [--from=<server> | --only-from=<server>] [--to=<tree>] [VAR=VALUE]... <command> [<argument>] | 46 | --server=<server> Fetch rocks/rockspecs from this server |
34 | 47 | (takes priority over config file) | |
35 | Variables from the "variables" table of the configuration file | 48 | --only-server=<server> Fetch rocks/rockspecs from this server only |
36 | can be overriden with VAR=VALUE assignments. | 49 | (overrides any entries in the config file) |
37 | 50 | --only-sources=<url> Restrict downloads to paths matching the | |
38 | --server=<server> Fetch rocks/rockspecs from this server | 51 | given URL. |
39 | (takes priority over config file) | 52 | --tree=<tree> Which tree to operate on. |
40 | --only-server=<server> Fetch rocks/rockspecs from this server only | 53 | --local Use the tree in the user's home directory.]]) |
41 | (overrides any entries in the config file) | 54 | print_section("VARIABLES") |
42 | --only-sources=<url> Restrict downloads to paths matching the | 55 | util.printout([[ |
43 | given URL. | 56 | Variables from the "variables" table of the configuration file |
44 | --tree=<tree> Which tree to operate on. | 57 | can be overriden with VAR=VALUE assignments.]]) |
45 | --local Use the tree in the user's home directory. | 58 | print_section("COMMANDS") |
46 | |||
47 | Supported commands: | ||
48 | ]]) | ||
49 | local names = {} | 59 | local names = {} |
50 | for name, command in pairs(commands) do | 60 | for name, command in pairs(commands) do |
51 | table.insert(names, name) | 61 | table.insert(names, name) |
@@ -53,18 +63,26 @@ Supported commands: | |||
53 | table.sort(names) | 63 | table.sort(names) |
54 | for _, name in ipairs(names) do | 64 | for _, name in ipairs(names) do |
55 | local command = commands[name] | 65 | local command = commands[name] |
56 | util.printout(name, command.help_summary) | 66 | util.printout("", name) |
67 | util.printout("\t", command.help_summary) | ||
57 | end | 68 | end |
69 | print_section("CONFIGURATION") | ||
70 | util.printout([[ | ||
71 | Using system configuration file: ]]..sys_file .. " (" .. (sys_ok and "ok" or "failed") ..[[) | ||
72 | and user configuration file: ]]..home_file .. " (" .. (home_ok and "ok" or "failed") ..")\n") | ||
58 | else | 73 | else |
59 | command = command:gsub("-", "_") | 74 | command = command:gsub("-", "_") |
60 | if commands[command] then | 75 | if commands[command] then |
61 | local arguments = commands[command].help_arguments or "<argument>" | 76 | local arguments = commands[command].help_arguments or "<argument>" |
62 | util.printout() | 77 | print_banner() |
63 | util.printout(program_name.." "..command.." "..arguments) | 78 | print_section("NAME") |
64 | util.printout() | 79 | util.printout("\t"..program_name.." "..command.." - "..commands[command].help_summary) |
65 | util.printout(command.." - "..commands[command].help_summary) | 80 | print_section("SYNOPSIS") |
66 | util.printout() | 81 | util.printout("\t"..program_name.." "..command.." "..arguments) |
67 | util.printout(commands[command].help) | 82 | print_section("DESCRIPTION") |
83 | util.printout("",(commands[command].help:gsub("\n","\n\t"):gsub("\n\t$",""))) | ||
84 | print_section("SEE ALSO") | ||
85 | util.printout("","'luarocks help' for general options and configuration.\n") | ||
68 | else | 86 | else |
69 | return nil, "Unknown command '"..command.."'" | 87 | return nil, "Unknown command '"..command.."'" |
70 | end | 88 | end |
diff --git a/src/luarocks/make.lua b/src/luarocks/make.lua index d39dd226..e20c399a 100644 --- a/src/luarocks/make.lua +++ b/src/luarocks/make.lua | |||
@@ -37,9 +37,6 @@ in the current directory. | |||
37 | function run(...) | 37 | function run(...) |
38 | local flags, rockspec = util.parse_flags(...) | 38 | local flags, rockspec = util.parse_flags(...) |
39 | assert(type(rockspec) == "string" or not rockspec) | 39 | assert(type(rockspec) == "string" or not rockspec) |
40 | |||
41 | local ok, err = fs.check_command_permissions(flags) | ||
42 | if not ok then return nil, err end | ||
43 | 40 | ||
44 | if not rockspec then | 41 | if not rockspec then |
45 | local files = fs.list_dir(fs.current_dir()) | 42 | local files = fs.list_dir(fs.current_dir()) |
@@ -64,6 +61,8 @@ function run(...) | |||
64 | local rspec, err, errcode = fetch.load_rockspec(rockspec) | 61 | local rspec, err, errcode = fetch.load_rockspec(rockspec) |
65 | return pack.pack_binary_rock(rspec.name, rspec.version, build.build_rockspec, rockspec, false, true) | 62 | return pack.pack_binary_rock(rspec.name, rspec.version, build.build_rockspec, rockspec, false, true) |
66 | else | 63 | else |
64 | local ok, err = fs.check_command_permissions(flags) | ||
65 | if not ok then return nil, err end | ||
67 | return build.build_rockspec(rockspec, false, true) | 66 | return build.build_rockspec(rockspec, false, true) |
68 | end | 67 | end |
69 | end | 68 | end |
diff --git a/src/luarocks/persist.lua b/src/luarocks/persist.lua index 91c28a32..6d411e0f 100644 --- a/src/luarocks/persist.lua +++ b/src/luarocks/persist.lua | |||
@@ -20,11 +20,17 @@ function load_into_table(filename, tbl) | |||
20 | 20 | ||
21 | local chunk, err = loadfile(filename) | 21 | local chunk, err = loadfile(filename) |
22 | if not chunk then | 22 | if not chunk then |
23 | return nil, err | 23 | if err:sub(1,5) ~= filename:sub(1,5) then |
24 | return false, err | ||
25 | end | ||
26 | return nil, "Error loading file: "..err | ||
24 | end | 27 | end |
25 | local result = tbl or {} | 28 | local result = tbl or {} |
26 | setfenv(chunk, result) | 29 | setfenv(chunk, result) |
27 | chunk() | 30 | local ok, err = pcall(chunk) |
31 | if not ok then | ||
32 | return nil, "Error running file: "..err | ||
33 | end | ||
28 | return result | 34 | return result |
29 | end | 35 | end |
30 | 36 | ||