aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/luarocks/cfg.lua23
-rw-r--r--src/luarocks/command_line.lua29
-rw-r--r--src/luarocks/fs/lua.lua52
-rw-r--r--src/luarocks/fs/win32/tools.lua10
-rw-r--r--src/luarocks/manif.lua28
-rw-r--r--src/luarocks/path.lua103
-rw-r--r--src/luarocks/rep.lua13
-rw-r--r--src/luarocks/validate.lua5
8 files changed, 160 insertions, 103 deletions
diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua
index c39056b4..220e7b29 100644
--- a/src/luarocks/cfg.lua
+++ b/src/luarocks/cfg.lua
@@ -1,6 +1,6 @@
1 1
2local rawset, next, table, pairs, print, require, io, os, setmetatable, pcall, ipairs, package = 2local rawset, next, table, pairs, print, require, io, os, setmetatable, pcall, ipairs, package, type =
3 rawset, next, table, pairs, print, require, io, os, setmetatable, pcall, ipairs, package 3 rawset, next, table, pairs, print, require, io, os, setmetatable, pcall, ipairs, package, type
4 4
5--- Configuration for LuaRocks. 5--- Configuration for LuaRocks.
6-- Tries to load the user's configuration file and 6-- Tries to load the user's configuration file and
@@ -22,6 +22,8 @@ if not ok then
22 config = {} 22 config = {}
23end 23end
24 24
25_M.config = config
26
25program_version = "2.0.2" 27program_version = "2.0.2"
26user_agent = "LuaRocks/"..program_version 28user_agent = "LuaRocks/"..program_version
27 29
@@ -117,15 +119,10 @@ end
117 119
118-- Configure defaults: 120-- Configure defaults:
119 121
120local root = config.LUAROCKS_ROCKS_TREE or home_tree 122local root = rocks_trees[#rocks_trees]
121local defaults = { 123local defaults = {
122 root_dir = root,
123 rocks_dir = root.."/lib/luarocks/rocks",
124 lua_modules_path = "/share/lua/5.1/", 124 lua_modules_path = "/share/lua/5.1/",
125 lib_modules_path = "/lib/lua/5.1/", 125 lib_modules_path = "/lib/lua/5.1/",
126 deploy_bin_dir = root.."/bin/",
127 deploy_lua_dir = root.."/share/lua/5.1/",
128 deploy_lib_dir = root.."/lib/lua/5.1/",
129 126
130 arch = "unknown", 127 arch = "unknown",
131 lib_extension = "unknown", 128 lib_extension = "unknown",
@@ -289,7 +286,13 @@ setmetatable(_M, cfg_mt)
289 286
290 287
291for _,tree in ipairs(rocks_trees) do 288for _,tree in ipairs(rocks_trees) do
292 package.path = tree..lua_modules_path.."/?.lua;"..tree..lua_modules_path.."/?/init.lua;"..package.path 289 if type(tree) == "string" then
293 package.cpath = tree..lib_modules_path.."/?."..lib_extension..";"..package.cpath 290 package.path = tree..lua_modules_path.."/?.lua;"..tree..lua_modules_path.."/?/init.lua;"..package.path
291 package.cpath = tree..lib_modules_path.."/?."..lib_extension..";"..package.cpath
292 else
293 package.path = (tree.lua_dir or tree.root..lua_modules_path).."/?.lua;"..
294 (tree.lua_dir or tree.root..lua_modules_path).."/?/init.lua;"..package.path
295 package.cpath = (tree.lib_dir or tree.root..lib_modules_path).."/?."..lib_extension..";"..package.cpath
296 end
294end 297end
295 298
diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua
index f2afc16a..d501d121 100644
--- a/src/luarocks/command_line.lua
+++ b/src/luarocks/command_line.lua
@@ -21,6 +21,18 @@ local function die(message)
21 os.exit(1) 21 os.exit(1)
22end 22end
23 23
24local function is_writable(tree)
25 if type(tree) == "string" then
26 return fs.make_dir(tree) and fs.is_writable(tree)
27 else
28 writable = true
29 for k, v in pairs(tree) do
30 writable = writable and fs.make_dir(v) and fs.is_writable(v)
31 end
32 return writable
33 end
34end
35
24--- Main command-line processor. 36--- Main command-line processor.
25-- Parses input arguments and calls the appropriate driver function 37-- Parses input arguments and calls the appropriate driver function
26-- to execute the action requested on the command-line, forwarding 38-- to execute the action requested on the command-line, forwarding
@@ -45,6 +57,7 @@ function run_command(...)
45 end 57 end
46 local nonflags = { util.parse_flags(unpack(args)) } 58 local nonflags = { util.parse_flags(unpack(args)) }
47 local flags = table.remove(nonflags, 1) 59 local flags = table.remove(nonflags, 1)
60 cfg.flags = flags
48 61
49 if flags["to"] then 62 if flags["to"] then
50 if flags["to"] == true then 63 if flags["to"] == true then
@@ -60,24 +73,28 @@ function run_command(...)
60 local trees = cfg.rocks_trees 73 local trees = cfg.rocks_trees
61 for i = #trees, 1, -1 do 74 for i = #trees, 1, -1 do
62 local tree = trees[i] 75 local tree = trees[i]
63 if fs.make_dir(tree) and fs.is_writable(tree) then 76 if is_writable(tree) then
64 cfg.root_dir = tree 77 cfg.root_dir = tree
65 cfg.rocks_dir = path.rocks_dir(tree) 78 cfg.rocks_dir = path.rocks_dir(tree)
66 cfg.deploy_bin_dir = rawget(cfg, "deploy_bin_dir") or path.deploy_bin_dir(tree) 79 cfg.deploy_bin_dir = path.deploy_bin_dir(tree)
67 cfg.deploy_lua_dir = rawget(cfg, "deploy_lua_dir") or path.deploy_lua_dir(tree) 80 cfg.deploy_lua_dir = path.deploy_lua_dir(tree)
68 cfg.deploy_lib_dir = rawget(cfg, "deploy_lib_dir") or path.deploy_lib_dir(tree) 81 cfg.deploy_lib_dir = path.deploy_lib_dir(tree)
69 break 82 break
70 end 83 end
71 end 84 end
72 end 85 end
73 86
74 cfg.root_dir = cfg.root_dir:gsub("/+$", "") 87 if type(cfg.root_dir) == "string" then
88 cfg.root_dir = cfg.root_dir:gsub("/+$", "")
89 else
90 cfg.root_dir.root = cfg.root_dir.root:gsub("/+$", "")
91 end
75 cfg.rocks_dir = cfg.rocks_dir:gsub("/+$", "") 92 cfg.rocks_dir = cfg.rocks_dir:gsub("/+$", "")
76 cfg.deploy_bin_dir = cfg.deploy_bin_dir:gsub("/+$", "") 93 cfg.deploy_bin_dir = cfg.deploy_bin_dir:gsub("/+$", "")
77 cfg.deploy_lua_dir = cfg.deploy_lua_dir:gsub("/+$", "") 94 cfg.deploy_lua_dir = cfg.deploy_lua_dir:gsub("/+$", "")
78 cfg.deploy_lib_dir = cfg.deploy_lib_dir:gsub("/+$", "") 95 cfg.deploy_lib_dir = cfg.deploy_lib_dir:gsub("/+$", "")
79 96
80 cfg.variables.ROCKS_TREE = cfg.root_dir 97 cfg.variables.ROCKS_TREE = cfg.rocks_dir
81 cfg.variables.SCRIPTS_DIR = cfg.deploy_bin_dir 98 cfg.variables.SCRIPTS_DIR = cfg.deploy_bin_dir
82 99
83 if flags["from"] then 100 if flags["from"] then
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua
index 3314d394..220c046d 100644
--- a/src/luarocks/fs/lua.lua
+++ b/src/luarocks/fs/lua.lua
@@ -8,7 +8,8 @@ local fs = require("luarocks.fs")
8local cfg = require("luarocks.cfg") 8local cfg = require("luarocks.cfg")
9local dir = require("luarocks.dir") 9local dir = require("luarocks.dir")
10 10
11local zip_ok, zip = pcall(require, "luarocks.tools.zip") 11local zip_ok, lrzip = pcall(require, "luarocks.tools.zip")
12local unzip_ok, luazip = pcall(require, "zip"); _G.zip = nil
12local lfs_ok, lfs = pcall(require, "lfs") 13local lfs_ok, lfs = pcall(require, "lfs")
13local curl_ok, curl = pcall(require, "luacurl") 14local curl_ok, curl = pcall(require, "luacurl")
14local md5_ok, md5 = pcall(require, "md5") 15local md5_ok, md5 = pcall(require, "md5")
@@ -18,7 +19,7 @@ local tar = require("luarocks.tools.tar")
18local patch = require("luarocks.tools.patch") 19local patch = require("luarocks.tools.patch")
19 20
20local dir_stack = {} 21local dir_stack = {}
21 22
22math.randomseed(os.time()) 23math.randomseed(os.time())
23 24
24dir_separator = "/" 25dir_separator = "/"
@@ -29,7 +30,7 @@ dir_separator = "/"
29-- @return string: Quoted argument. 30-- @return string: Quoted argument.
30function Q(arg) 31function Q(arg)
31 assert(type(arg) == "string") 32 assert(type(arg) == "string")
32 33
33 -- FIXME Unix-specific 34 -- FIXME Unix-specific
34 return "'" .. arg:gsub("\\", "\\\\"):gsub("'", "'\\''") .. "'" 35 return "'" .. arg:gsub("\\", "\\\\"):gsub("'", "'\\''") .. "'"
35end 36end
@@ -82,7 +83,7 @@ end
82-- otherwise. 83-- otherwise.
83function execute(command, ...) 84function execute(command, ...)
84 assert(type(command) == "string") 85 assert(type(command) == "string")
85 86
86 for _, arg in ipairs({...}) do 87 for _, arg in ipairs({...}) do
87 assert(type(arg) == "string") 88 assert(type(arg) == "string")
88 command = command .. " " .. fs.Q(arg) 89 command = command .. " " .. fs.Q(arg)
@@ -243,7 +244,7 @@ end
243-- @return boolean or (boolean, string): true on success, false on failure 244-- @return boolean or (boolean, string): true on success, false on failure
244local function recursive_copy(src, dest) 245local function recursive_copy(src, dest)
245 local srcmode = lfs.attributes(src, "mode") 246 local srcmode = lfs.attributes(src, "mode")
246 247
247 if srcmode == "file" then 248 if srcmode == "file" then
248 local ok = fs.copy(src, dest) 249 local ok = fs.copy(src, dest)
249 if not ok then return false end 250 if not ok then return false end
@@ -268,7 +269,7 @@ end
268function copy_contents(src, dest) 269function copy_contents(src, dest)
269 assert(src and dest) 270 assert(src and dest)
270 assert(lfs.attributes(src, "mode") == "directory") 271 assert(lfs.attributes(src, "mode") == "directory")
271 272
272 for file in lfs.dir(src) do 273 for file in lfs.dir(src) do
273 if file ~= "." and file ~= ".." then 274 if file ~= "." and file ~= ".." then
274 local ok = recursive_copy(dir.path(src, file), dest) 275 local ok = recursive_copy(dir.path(src, file), dest)
@@ -287,7 +288,7 @@ end
287-- or nil and an error message on failure. 288-- or nil and an error message on failure.
288local function recursive_delete(src) 289local function recursive_delete(src)
289 local srcmode = lfs.attributes(src, "mode") 290 local srcmode = lfs.attributes(src, "mode")
290 291
291 if srcmode == "file" then 292 if srcmode == "file" then
292 return os.remove(src) 293 return os.remove(src)
293 elseif srcmode == "directory" then 294 elseif srcmode == "directory" then
@@ -312,7 +313,7 @@ function delete(arg)
312 return recursive_delete(arg) or false 313 return recursive_delete(arg) or false
313end 314end
314 315
315--- List the contents of a directory. 316--- List the contents of a directory.
316-- @param at string or nil: directory to list (will be the current 317-- @param at string or nil: directory to list (will be the current
317-- directory if none is given). 318-- directory if none is given).
318-- @return table: an array of strings with the filenames representing 319-- @return table: an array of strings with the filenames representing
@@ -351,7 +352,7 @@ local function recursive_find(cwd, prefix, result)
351 end 352 end
352end 353end
353 354
354--- Recursively scan the contents of a directory. 355--- Recursively scan the contents of a directory.
355-- @param at string or nil: directory to scan (will be the current 356-- @param at string or nil: directory to scan (will be the current
356-- directory if none is given). 357-- directory if none is given).
357-- @return table: an array of strings with the filenames representing 358-- @return table: an array of strings with the filenames representing
@@ -405,17 +406,38 @@ end
405 406
406if zip_ok then 407if zip_ok then
407 408
408local function zip(zipfile, ...) 409function zip(zipfile, ...)
409 return zip.zip(zipfile, ...) 410 return lrzip.zip(zipfile, ...)
411end
412
410end 413end
411 414
415if unzip_ok then
412--- Uncompress files from a .zip archive. 416--- Uncompress files from a .zip archive.
413-- @param zipfile string: pathname of .zip archive to be extracted. 417-- @param zipfile string: pathname of .zip archive to be extracted.
414-- @return boolean: true on success, false on failure. 418-- @return boolean: true on success, false on failure.
415function unzip(zipfile) 419function unzip(zipfile)
416 assert(zipfile) 420 local zipfile, err = luazip.open(zipfile)
417 -- FIXME!!!! 421 if not zipfile then return nil, err end
418 return fs.execute("unzip", zipfile) 422 local files = zipfile:files()
423 local file = files()
424 repeat
425 if file.filename:sub(#file.filename) == "/" then
426 fs.make_dir(dir.path(fs.current_dir(), file.filename))
427 else
428 local rf, err = zipfile:open(file.filename)
429 if not rf then zipfile:close(); return nil, err end
430 local contents = rf:read("*a")
431 rf:close()
432 local wf, err = io.open(dir.path(fs.current_dir(), file.filename), "wb")
433 if not wf then zipfile:close(); return nil, err end
434 wf:write(contents)
435 wf:close()
436 end
437 file = files()
438 until not file
439 zipfile:close()
440 return true
419end 441end
420 442
421end 443end
@@ -437,7 +459,7 @@ function download(url, filename)
437 assert(type(url) == "string") 459 assert(type(url) == "string")
438 assert(type(filename) == "string" or not filename) 460 assert(type(filename) == "string" or not filename)
439 461
440 filename = filename or dir.base_name(url) 462 filename = dir.path(fs.current_dir(), filename or dir.base_name(url))
441 463
442 local c = curl.new() 464 local c = curl.new()
443 if not c then return false end 465 if not c then return false end
diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua
index 2bd2b8c5..0555a3b1 100644
--- a/src/luarocks/fs/win32/tools.lua
+++ b/src/luarocks/fs/win32/tools.lua
@@ -206,7 +206,7 @@ function delete(arg)
206 return fs.execute_string("rm -rf " .. fs.Q(arg) .. " 1> NUL 2> NUL") 206 return fs.execute_string("rm -rf " .. fs.Q(arg) .. " 1> NUL 2> NUL")
207end 207end
208 208
209--- List the contents of a directory. 209--- List the contents of a directory.
210-- @param at string or nil: directory to list (will be the current 210-- @param at string or nil: directory to list (will be the current
211-- directory if none is given). 211-- directory if none is given).
212-- @return table: an array of strings with the filenames representing 212-- @return table: an array of strings with the filenames representing
@@ -229,7 +229,7 @@ function list_dir(at)
229 return result 229 return result
230end 230end
231 231
232--- Recursively scan the contents of a directory. 232--- Recursively scan the contents of a directory.
233-- @param at string or nil: directory to scan (will be the current 233-- @param at string or nil: directory to scan (will be the current
234-- directory if none is given). 234-- directory if none is given).
235-- @return table: an array of strings with the filenames representing 235-- @return table: an array of strings with the filenames representing
@@ -243,7 +243,7 @@ function find(at)
243 return {} 243 return {}
244 end 244 end
245 local result = {} 245 local result = {}
246 local pipe = io.popen(command_at(at, "find 2> NUL")) 246 local pipe = io.popen(command_at(at, "find 2> NUL"))
247 for file in pipe:lines() do 247 for file in pipe:lines() do
248 -- Windows find is a bit different 248 -- Windows find is a bit different
249 if file:sub(1,2)==".\\" then file=file:sub(3) end 249 if file:sub(1,2)==".\\" then file=file:sub(3) end
@@ -266,7 +266,7 @@ function download(url, filename)
266 assert(type(filename) == "string" or not filename) 266 assert(type(filename) == "string" or not filename)
267 local wget_cmd = "wget --cache=off --user-agent="..cfg.user_agent.." --quiet --continue " 267 local wget_cmd = "wget --cache=off --user-agent="..cfg.user_agent.." --quiet --continue "
268 268
269 if filename then 269 if filename then
270 return fs.execute(wget_cmd.." --output-document ", filename, url) 270 return fs.execute(wget_cmd.." --output-document ", filename, url)
271 else 271 else
272 return fs.execute(wget_cmd, url) 272 return fs.execute(wget_cmd, url)
@@ -307,7 +307,7 @@ end
307-- @return boolean or (boolean, string): true on success, false and an error message on failure. 307-- @return boolean or (boolean, string): true on success, false and an error message on failure.
308function unpack_archive(archive) 308function unpack_archive(archive)
309 assert(type(archive) == "string") 309 assert(type(archive) == "string")
310 310
311 local ok 311 local ok
312 if archive:match("%.tar%.gz$") then 312 if archive:match("%.tar%.gz$") then
313 ok = gunzip(archive) 313 ok = gunzip(archive)
diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua
index 9f6f6fa2..7f0a4ea0 100644
--- a/src/luarocks/manif.lua
+++ b/src/luarocks/manif.lua
@@ -56,7 +56,7 @@ function make_rock_manifest(name, version)
56 local last_name 56 local last_name
57 for name in file:gmatch("[^/]+") do 57 for name in file:gmatch("[^/]+") do
58 local next = walk[name] 58 local next = walk[name]
59 if not next then 59 if not next then
60 next = {} 60 next = {}
61 walk[name] = next 61 walk[name] = next
62 end 62 end
@@ -81,7 +81,7 @@ end
81-- or nil followed by an error message and an optional error code. 81-- or nil followed by an error message and an optional error code.
82function load_manifest(repo_url) 82function load_manifest(repo_url)
83 assert(type(repo_url) == "string") 83 assert(type(repo_url) == "string")
84 84
85 if manif_core.manifest_cache[repo_url] then 85 if manif_core.manifest_cache[repo_url] then
86 return manif_core.manifest_cache[repo_url] 86 return manif_core.manifest_cache[repo_url]
87 end 87 end
@@ -141,7 +141,7 @@ local function sort_pkgs(a, b)
141 141
142 local na, va = a:match("(.*)/(.*)$") 142 local na, va = a:match("(.*)/(.*)$")
143 local nb, vb = b:match("(.*)/(.*)$") 143 local nb, vb = b:match("(.*)/(.*)$")
144 144
145 return (na == nb) and deps.compare_versions(va, vb) or na < nb 145 return (na == nb) and deps.compare_versions(va, vb) or na < nb
146end 146end
147 147
@@ -150,7 +150,7 @@ end
150-- and values arrays of strings with packages names in "name/version" format. 150-- and values arrays of strings with packages names in "name/version" format.
151local function sort_package_matching_table(tbl) 151local function sort_package_matching_table(tbl)
152 assert(type(tbl) == "table") 152 assert(type(tbl) == "table")
153 153
154 if next(tbl) then 154 if next(tbl) then
155 for item, pkgs in pairs(tbl) do 155 for item, pkgs in pairs(tbl) do
156 if #pkgs > 1 then 156 if #pkgs > 1 then
@@ -275,8 +275,7 @@ end
275function update_manifest(name, version, repo) 275function update_manifest(name, version, repo)
276 assert(type(name) == "string") 276 assert(type(name) == "string")
277 assert(type(version) == "string") 277 assert(type(version) == "string")
278 assert(type(repo) == "string" or not repo) 278 repo = path.rocks_dir(repo or cfg.root_dir)
279 repo = repo or cfg.rocks_dir
280 279
281 print("Updating manifest for "..repo) 280 print("Updating manifest for "..repo)
282 281
@@ -297,7 +296,7 @@ function update_manifest(name, version, repo)
297 296
298 local ok, err = store_results(results, manifest) 297 local ok, err = store_results(results, manifest)
299 if not ok then return nil, err end 298 if not ok then return nil, err end
300 299
301 return save_table(repo, "manifest", manifest) 300 return save_table(repo, "manifest", manifest)
302end 301end
303 302
@@ -307,7 +306,6 @@ end
307 306
308local function find_providers(file, root) 307local function find_providers(file, root)
309 assert(type(file) == "string") 308 assert(type(file) == "string")
310 assert(type(root) == "string" or not root)
311 root = root or cfg.root_dir 309 root = root or cfg.root_dir
312 310
313 local manifest = manif_core.load_local_manifest(path.rocks_dir(root)) 311 local manifest = manif_core.load_local_manifest(path.rocks_dir(root))
@@ -319,22 +317,22 @@ local function find_providers(file, root)
319 local deploy_lib = path.deploy_lib_dir(root) 317 local deploy_lib = path.deploy_lib_dir(root)
320 local key, manifest_tbl 318 local key, manifest_tbl
321 319
322 if starts_with(file, deploy_bin) then 320 if starts_with(file, deploy_lua) then
323 manifest_tbl = manifest.commands
324 key = file:sub(#deploy_bin+1):gsub("^/*", "")
325 elseif starts_with(file, deploy_lua) then
326 manifest_tbl = manifest.modules 321 manifest_tbl = manifest.modules
327 key = path.path_to_module(file:sub(#deploy_lua+1)) 322 key = path.path_to_module(file:sub(#deploy_lua+1):gsub("\\", "/"))
328 elseif starts_with(file, deploy_lib) then 323 elseif starts_with(file, deploy_lib) then
329 manifest_tbl = manifest.modules 324 manifest_tbl = manifest.modules
330 key = path.path_to_module(file:sub(#deploy_lib+1)) 325 key = path.path_to_module(file:sub(#deploy_lib+1):gsub("\\", "/"))
326 elseif starts_with(file, deploy_bin) then
327 manifest_tbl = manifest.commands
328 key = file:sub(#deploy_bin+1):gsub("^[\\/]*", "")
331 else 329 else
332 assert(false, "Assertion failed: '"..file.."' is not a deployed file.") 330 assert(false, "Assertion failed: '"..file.."' is not a deployed file.")
333 end 331 end
334 332
335 local providers = manifest_tbl[key] 333 local providers = manifest_tbl[key]
336 if not providers then 334 if not providers then
337 return nil, "File "..file.." is not tracked by LuaRocks." 335 return nil, "untracked"
338 end 336 end
339 return providers 337 return providers
340end 338end
diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua
index 596b73b8..05e04b43 100644
--- a/src/luarocks/path.lua
+++ b/src/luarocks/path.lua
@@ -17,28 +17,48 @@ function rockspec_name_from_rock(rock_name)
17end 17end
18 18
19function rocks_dir(repo) 19function rocks_dir(repo)
20 assert(type(repo) == "string") 20 if type(repo) == "string" then
21 return dir.path(repo, "lib", "luarocks", "rocks") 21 return dir.path(repo, "lib", "luarocks", "rocks")
22 else
23 assert(type(repo) == "table")
24 return repo.rocks_dir or dir.path(repo.root, "lib", "luarocks", "rocks")
25 end
22end 26end
23 27
24function deploy_bin_dir(repo) 28function deploy_bin_dir(repo)
25 assert(type(repo) == "string") 29 if type(repo) == "string" then
26 return dir.path(repo, "bin") 30 return dir.path(repo, "bin")
31 else
32 assert(type(repo) == "table")
33 return repo.bin_dir or dir.path(repo.root, "bin")
34 end
27end 35end
28 36
29function deploy_lua_dir(repo) 37function deploy_lua_dir(repo)
30 assert(type(repo) == "string") 38 if type(repo) == "string" then
31 return dir.path(repo, "share", "lua", "5.1") 39 return dir.path(repo, "share", "lua", "5.1")
40 else
41 assert(type(repo) == "table")
42 return repo.lua_dir or dir.path(repo.root, "share", "lua", "5.1")
43 end
32end 44end
33 45
34function deploy_lib_dir(repo) 46function deploy_lib_dir(repo)
35 assert(type(repo) == "string") 47 if type(repo) == "string" then
36 return dir.path(repo, "lib", "lua", "5.1") 48 return dir.path(repo, "lib", "lua", "5.1")
49 else
50 assert(type(repo) == "table")
51 return repo.lib_dir or dir.path(repo.root, "lib", "lua", "5.1")
52 end
37end 53end
38 54
39function manifest_file(repo) 55function manifest_file(repo)
40 assert(type(repo) == "string") 56 if type(repo) == "string" then
41 return dir.path(repo, "lib", "luarocks", "rocks", "manifest") 57 return dir.path(repo, "lib", "luarocks", "rocks", "manifest")
58 else
59 assert(type(repo) == "table")
60 return (repo.rocks_dir and dir.path(repo.rocks_dir, "manifest")) or dir.path(repo.root, "lib", "luarocks", "rocks", "manifest")
61 end
42end 62end
43 63
44--- Get the repository directory for all versions of a package. 64--- Get the repository directory for all versions of a package.
@@ -46,11 +66,10 @@ end
46-- @return string: The resulting path -- does not guarantee that 66-- @return string: The resulting path -- does not guarantee that
47-- @param rocks_dir string or nil: If given, specifies the local repository to use. 67-- @param rocks_dir string or nil: If given, specifies the local repository to use.
48-- the package (and by extension, the path) exists. 68-- the package (and by extension, the path) exists.
49function versions_dir(name, rocks_dir) 69function versions_dir(name, repo)
50 assert(type(name) == "string") 70 assert(type(name) == "string")
51 assert(not rocks_dir or type(rocks_dir) == "string") 71 repo = repo or cfg.root_dir
52 72 return dir.path(rocks_dir(repo), name)
53 return dir.path(rocks_dir or cfg.rocks_dir, name)
54end 73end
55 74
56--- Get the local installation directory (prefix) for a package. 75--- Get the local installation directory (prefix) for a package.
@@ -59,12 +78,11 @@ end
59-- @param rocks_dir string or nil: If given, specifies the local repository to use. 78-- @param rocks_dir string or nil: If given, specifies the local repository to use.
60-- @return string: The resulting path -- does not guarantee that 79-- @return string: The resulting path -- does not guarantee that
61-- the package (and by extension, the path) exists. 80-- the package (and by extension, the path) exists.
62function install_dir(name, version, rocks_dir) 81function install_dir(name, version, repo)
63 assert(type(name) == "string") 82 assert(type(name) == "string")
64 assert(type(version) == "string") 83 assert(type(version) == "string")
65 assert(not rocks_dir or type(rocks_dir) == "string") 84 repo = repo or cfg.root_dir
66 85 return dir.path(rocks_dir(repo), name, version)
67 return dir.path(rocks_dir or cfg.rocks_dir, name, version)
68end 86end
69 87
70--- Get the local filename of the rockspec of an installed rock. 88--- Get the local filename of the rockspec of an installed rock.
@@ -73,12 +91,11 @@ end
73-- @param rocks_dir string or nil: If given, specifies the local repository to use. 91-- @param rocks_dir string or nil: If given, specifies the local repository to use.
74-- @return string: The resulting path -- does not guarantee that 92-- @return string: The resulting path -- does not guarantee that
75-- the package (and by extension, the file) exists. 93-- the package (and by extension, the file) exists.
76function rockspec_file(name, version, rocks_dir) 94function rockspec_file(name, version, repo)
77 assert(type(name) == "string") 95 assert(type(name) == "string")
78 assert(type(version) == "string") 96 assert(type(version) == "string")
79 assert(not rocks_dir or type(rocks_dir) == "string") 97 repo = repo or cfg.root_dir
80 98 return dir.path(rocks_dir(repo), name, version, name.."-"..version..".rockspec")
81 return dir.path(rocks_dir or cfg.rocks_dir, name, version, name.."-"..version..".rockspec")
82end 99end
83 100
84--- Get the local filename of the rock_manifest file of an installed rock. 101--- Get the local filename of the rock_manifest file of an installed rock.
@@ -87,12 +104,11 @@ end
87-- @param rocks_dir string or nil: If given, specifies the local repository to use. 104-- @param rocks_dir string or nil: If given, specifies the local repository to use.
88-- @return string: The resulting path -- does not guarantee that 105-- @return string: The resulting path -- does not guarantee that
89-- the package (and by extension, the file) exists. 106-- the package (and by extension, the file) exists.
90function rock_manifest_file(name, version, rocks_dir) 107function rock_manifest_file(name, version, repo)
91 assert(type(name) == "string") 108 assert(type(name) == "string")
92 assert(type(version) == "string") 109 assert(type(version) == "string")
93 assert(not rocks_dir or type(rocks_dir) == "string") 110 repo = repo or cfg.root_dir
94 111 return dir.path(rocks_dir(repo), name, version, "rock_manifest")
95 return dir.path(rocks_dir or cfg.rocks_dir, name, version, "rock_manifest")
96end 112end
97 113
98--- Get the local installation directory for C libraries of a package. 114--- Get the local installation directory for C libraries of a package.
@@ -101,12 +117,11 @@ end
101-- @param rocks_dir string or nil: If given, specifies the local repository to use. 117-- @param rocks_dir string or nil: If given, specifies the local repository to use.
102-- @return string: The resulting path -- does not guarantee that 118-- @return string: The resulting path -- does not guarantee that
103-- the package (and by extension, the path) exists. 119-- the package (and by extension, the path) exists.
104function lib_dir(name, version, rocks_dir) 120function lib_dir(name, version, repo)
105 assert(type(name) == "string") 121 assert(type(name) == "string")
106 assert(type(version) == "string") 122 assert(type(version) == "string")
107 assert(not rocks_dir or type(rocks_dir) == "string") 123 repo = repo or cfg.root_dir
108 124 return dir.path(rocks_dir(repo), name, version, "lib")
109 return dir.path(rocks_dir or cfg.rocks_dir, name, version, "lib")
110end 125end
111 126
112--- Get the local installation directory for Lua modules of a package. 127--- Get the local installation directory for Lua modules of a package.
@@ -115,12 +130,11 @@ end
115-- @param rocks_dir string or nil: If given, specifies the local repository to use. 130-- @param rocks_dir string or nil: If given, specifies the local repository to use.
116-- @return string: The resulting path -- does not guarantee that 131-- @return string: The resulting path -- does not guarantee that
117-- the package (and by extension, the path) exists. 132-- the package (and by extension, the path) exists.
118function lua_dir(name, version, rocks_dir) 133function lua_dir(name, version, repo)
119 assert(type(name) == "string") 134 assert(type(name) == "string")
120 assert(type(version) == "string") 135 assert(type(version) == "string")
121 assert(not rocks_dir or type(rocks_dir) == "string") 136 repo = repo or cfg.root_dir
122 137 return dir.path(rocks_dir(repo), name, version, "lua")
123 return dir.path(rocks_dir or cfg.rocks_dir, name, version, "lua")
124end 138end
125 139
126--- Get the local installation directory for documentation of a package. 140--- Get the local installation directory for documentation of a package.
@@ -129,12 +143,11 @@ end
129-- @param rocks_dir string or nil: If given, specifies the local repository to use. 143-- @param rocks_dir string or nil: If given, specifies the local repository to use.
130-- @return string: The resulting path -- does not guarantee that 144-- @return string: The resulting path -- does not guarantee that
131-- the package (and by extension, the path) exists. 145-- the package (and by extension, the path) exists.
132function doc_dir(name, version, rocks_dir) 146function doc_dir(name, version, repo)
133 assert(type(name) == "string") 147 assert(type(name) == "string")
134 assert(type(version) == "string") 148 assert(type(version) == "string")
135 assert(not rocks_dir or type(rocks_dir) == "string") 149 repo = repo or cfg.root_dir
136 150 return dir.path(rocks_dir(repo), name, version, "doc")
137 return dir.path(rocks_dir or cfg.rocks_dir, name, version, "doc")
138end 151end
139 152
140--- Get the local installation directory for configuration files of a package. 153--- Get the local installation directory for configuration files of a package.
@@ -143,12 +156,11 @@ end
143-- @param rocks_dir string or nil: If given, specifies the local repository to use. 156-- @param rocks_dir string or nil: If given, specifies the local repository to use.
144-- @return string: The resulting path -- does not guarantee that 157-- @return string: The resulting path -- does not guarantee that
145-- the package (and by extension, the path) exists. 158-- the package (and by extension, the path) exists.
146function conf_dir(name, version, rocks_dir) 159function conf_dir(name, version, repo)
147 assert(type(name) == "string") 160 assert(type(name) == "string")
148 assert(type(version) == "string") 161 assert(type(version) == "string")
149 assert(not rocks_dir or type(rocks_dir) == "string") 162 repo = repo or cfg.root_dir
150 163 return dir.path(rocks_dir(repo), name, version, "conf")
151 return dir.path(rocks_dir or cfg.rocks_dir, name, version, "conf")
152end 164end
153 165
154--- Get the local installation directory for command-line scripts 166--- Get the local installation directory for command-line scripts
@@ -158,12 +170,11 @@ end
158-- @param rocks_dir string or nil: If given, specifies the local repository to use. 170-- @param rocks_dir string or nil: If given, specifies the local repository to use.
159-- @return string: The resulting path -- does not guarantee that 171-- @return string: The resulting path -- does not guarantee that
160-- the package (and by extension, the path) exists. 172-- the package (and by extension, the path) exists.
161function bin_dir(name, version, rocks_dir) 173function bin_dir(name, version, repo)
162 assert(type(name) == "string") 174 assert(type(name) == "string")
163 assert(type(version) == "string") 175 assert(type(version) == "string")
164 assert(not rocks_dir or type(rocks_dir) == "string") 176 repo = repo or cfg.root_dir
165 177 return dir.path(rocks_dir(repo), name, version, "bin")
166 return dir.path(rocks_dir or cfg.rocks_dir, name, version, "bin")
167end 178end
168 179
169--- Extract name, version and arch of a rock filename. 180--- Extract name, version and arch of a rock filename.
diff --git a/src/luarocks/rep.lua b/src/luarocks/rep.lua
index de6b01bb..8b42caa2 100644
--- a/src/luarocks/rep.lua
+++ b/src/luarocks/rep.lua
@@ -208,9 +208,16 @@ function deploy_files(name, version)
208 local target = dir.path(deploy_dir, parent_path, file) 208 local target = dir.path(deploy_dir, parent_path, file)
209 local ok, err 209 local ok, err
210 if fs.exists(target) then 210 if fs.exists(target) then
211 target, err = resolve_conflict(target, deploy_dir, name, version) 211 local new_target, err = resolve_conflict(target, deploy_dir, name, version)
212 if err then return nil, err.." Cannot install new version." end 212 if err == "untracked" then
213 end 213 if cfg.flags["force"] then
214 fs.delete(target)
215 else
216 return nil, "File "..file.." is not tracked by LuaRocks. Cannot install new version. Install with --force if you want to install anyway."
217 end
218 elseif err then return nil, err.." Cannot install new version."
219 else target = new_target end
220 end
214 fs.make_dir(dir.dir_name(target)) 221 fs.make_dir(dir.dir_name(target))
215 ok, err = move_fn(source, target) 222 ok, err = move_fn(source, target)
216 fs.remove_dir_tree_if_empty(dir.dir_name(source)) 223 fs.remove_dir_tree_if_empty(dir.dir_name(source))
diff --git a/src/luarocks/validate.lua b/src/luarocks/validate.lua
index b8b4edfd..ef402988 100644
--- a/src/luarocks/validate.lua
+++ b/src/luarocks/validate.lua
@@ -33,7 +33,7 @@ local function restore_settings(settings)
33 cfg.deploy_bin_dir = settings.deploy_bin_dir 33 cfg.deploy_bin_dir = settings.deploy_bin_dir
34 cfg.deploy_lua_dir = settings.deploy_lua_dir 34 cfg.deploy_lua_dir = settings.deploy_lua_dir
35 cfg.deploy_lib_dir = settings.deploy_lib_dir 35 cfg.deploy_lib_dir = settings.deploy_lib_dir
36 cfg.variables.ROCKS_TREE = settings.root_dir 36 cfg.variables.ROCKS_TREE = settings.rocks_dir
37 cfg.variables.SCRIPTS_DIR = settings.deploy_bin_dir 37 cfg.variables.SCRIPTS_DIR = settings.deploy_bin_dir
38 table.remove(cfg.rocks_servers, 1) 38 table.remove(cfg.rocks_servers, 1)
39end 39end
@@ -43,7 +43,7 @@ local function prepare_sandbox(file)
43 cfg.root_dir = root_dir 43 cfg.root_dir = root_dir
44 cfg.rocks_dir = path.rocks_dir(root_dir) 44 cfg.rocks_dir = path.rocks_dir(root_dir)
45 cfg.deploy_bin_dir = path.deploy_bin_dir(root_dir) 45 cfg.deploy_bin_dir = path.deploy_bin_dir(root_dir)
46 cfg.variables.ROCKS_TREE = cfg.root_dir 46 cfg.variables.ROCKS_TREE = cfg.rocks_dir
47 cfg.variables.SCRIPTS_DIR = cfg.deploy_bin_dir 47 cfg.variables.SCRIPTS_DIR = cfg.deploy_bin_dir
48 return root_dir 48 return root_dir
49end 49end
@@ -154,7 +154,6 @@ end
154 154
155function run(...) 155function run(...)
156 local flags, repo = util.parse_flags(...) 156 local flags, repo = util.parse_flags(...)
157 assert(type(repo) == "string" or not repo)
158 repo = repo or cfg.rocks_dir 157 repo = repo or cfg.rocks_dir
159 158
160 print("Verifying contents of "..repo) 159 print("Verifying contents of "..repo)