aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhisham <hisham@9ca3f7c1-7366-0410-b1a3-b5c78f85698c>2009-08-14 20:57:38 +0000
committerhisham <hisham@9ca3f7c1-7366-0410-b1a3-b5c78f85698c>2009-08-14 20:57:38 +0000
commitec074fcb99c44941c38775e51700d60cbd59cfd4 (patch)
tree56896b28c3f1b84a427563882f17e96f875dd50a /src
parent9f59a5c272af8d283ecc54b3578daaf64bd8612e (diff)
downloadluarocks-ec074fcb99c44941c38775e51700d60cbd59cfd4.tar.gz
luarocks-ec074fcb99c44941c38775e51700d60cbd59cfd4.tar.bz2
luarocks-ec074fcb99c44941c38775e51700d60cbd59cfd4.zip
further cleanup in fs abstractions
git-svn-id: http://luarocks.org/svn/luarocks/trunk@48 9ca3f7c1-7366-0410-b1a3-b5c78f85698c
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/cfg.lua13
-rw-r--r--src/luarocks/fs/lua.lua49
-rw-r--r--src/luarocks/fs/unix/tools.lua30
3 files changed, 55 insertions, 37 deletions
diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua
index ddcfac9d..bd3bdbc3 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 = 2local rawset, next, table, pairs, print, require, io, os, setmetatable, pcall, ipairs, package =
3 rawset, next, table, pairs, print, require, io, os, setmetatable, pcall 3 rawset, next, table, pairs, print, require, io, os, setmetatable, pcall, ipairs, package
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
@@ -109,6 +109,8 @@ local defaults = {
109 root_dir = root, 109 root_dir = root,
110 rocks_dir = root.."/lib/luarocks/rocks", 110 rocks_dir = root.."/lib/luarocks/rocks",
111 scripts_dir = root.."/bin/", 111 scripts_dir = root.."/bin/",
112 lua_modules_path = "/share/lua/5.1/",
113 bin_modules_path = "/lib/lua/5.1/",
112 lua_modules_dir = root.."/share/lua/5.1/", 114 lua_modules_dir = root.."/share/lua/5.1/",
113 bin_modules_dir = root.."/lib/lua/5.1/", 115 bin_modules_dir = root.."/lib/lua/5.1/",
114 116
@@ -269,3 +271,10 @@ local cfg_mt = {
269 end 271 end
270} 272}
271setmetatable(_M, cfg_mt) 273setmetatable(_M, cfg_mt)
274
275
276for _,tree in ipairs(rocks_trees) do
277 package.path = tree..lua_modules_path.."/?.lua;"..tree..lua_modules_path.."/?/init.lua;"..package.path
278 package.cpath = tree..bin_modules_path.."/?."..lib_extension..";"..package.cpath
279end
280
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua
index 013fad5f..f989b652 100644
--- a/src/luarocks/fs/lua.lua
+++ b/src/luarocks/fs/lua.lua
@@ -10,9 +10,9 @@ local dir = require("luarocks.dir")
10 10
11local zip_ok, zip = pcall(require, "luarocks.tools.zip") 11local zip_ok, zip = pcall(require, "luarocks.tools.zip")
12local lfs_ok, lfs = pcall(require, "lfs") 12local lfs_ok, lfs = pcall(require, "lfs")
13
14local curl_ok, curl = pcall(require, "luacurl") 13local curl_ok, curl = pcall(require, "luacurl")
15local md5_ok, md5 = pcall(require, "md5") 14local md5_ok, md5 = pcall(require, "md5")
15local posix_ok, posix = pcall(require, "posix")
16 16
17local tar = require("luarocks.tools.tar") 17local tar = require("luarocks.tools.tar")
18local patch = require("luarocks.tools.patch") 18local patch = require("luarocks.tools.patch")
@@ -468,6 +468,19 @@ end
468end 468end
469 469
470--------------------------------------------------------------------- 470---------------------------------------------------------------------
471-- POSIX functions
472---------------------------------------------------------------------
473
474if posix_ok then
475
476function chmod(file, mode)
477 local err = posix.chmod(file, mode)
478 return err == 0
479end
480
481end
482
483---------------------------------------------------------------------
471-- Other functions 484-- Other functions
472--------------------------------------------------------------------- 485---------------------------------------------------------------------
473 486
@@ -503,37 +516,3 @@ function move(src, dest)
503 end 516 end
504 return true 517 return true
505end 518end
506
507---------------------------------------------------------------------
508-- TODO These still reference external binaries
509---------------------------------------------------------------------
510
511--- Unpack an archive.
512-- Extract the contents of an archive, detecting its format by
513-- filename extension.
514-- @param archive string: Filename of archive.
515-- @return boolean or (boolean, string): true on success, false and an error message on failure.
516function unpack_archive(archive)
517 assert(type(archive) == "string")
518
519 local ok
520 if archive:match("%.tar%.gz$") or archive:match("%.tgz$") then
521 -- ok = fs.execute("tar zxvpf ", archive)
522 ok = fs.execute_string("gunzip -c "..archive.."|tar -xf -")
523 elseif archive:match("%.tar%.bz2$") then
524 -- ok = fs.execute("tar jxvpf ", archive)
525 ok = fs.execute_string("bunzip2 -c "..archive.."|tar -xf -")
526 elseif archive:match("%.zip$") then
527 ok = fs.execute("unzip ", archive)
528 elseif archive:match("%.lua$") or archive:match("%.c$") then
529 -- Ignore .lua and .c files; they don't need to be extracted.
530 return true
531 else
532 local ext = archive:match(".*(%..*)")
533 return false, "Unrecognized filename extension "..(ext or "")
534 end
535 if not ok then
536 return false, "Failed extracting "..archive
537 end
538 return true
539end
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua
index 71dfe074..b4cb43a7 100644
--- a/src/luarocks/fs/unix/tools.lua
+++ b/src/luarocks/fs/unix/tools.lua
@@ -321,3 +321,33 @@ function check_md5(file, md5sum)
321 return false 321 return false
322 end 322 end
323end 323end
324
325--- Unpack an archive.
326-- Extract the contents of an archive, detecting its format by
327-- filename extension.
328-- @param archive string: Filename of archive.
329-- @return boolean or (boolean, string): true on success, false and an error message on failure.
330function unpack_archive(archive)
331 assert(type(archive) == "string")
332
333 local ok
334 if archive:match("%.tar%.gz$") or archive:match("%.tgz$") then
335 -- ok = fs.execute("tar zxvpf ", archive)
336 ok = fs.execute_string("gunzip -c "..archive.."|tar -xf -")
337 elseif archive:match("%.tar%.bz2$") then
338 -- ok = fs.execute("tar jxvpf ", archive)
339 ok = fs.execute_string("bunzip2 -c "..archive.."|tar -xf -")
340 elseif archive:match("%.zip$") then
341 ok = fs.execute("unzip ", archive)
342 elseif archive:match("%.lua$") or archive:match("%.c$") then
343 -- Ignore .lua and .c files; they don't need to be extracted.
344 return true
345 else
346 local ext = archive:match(".*(%..*)")
347 return false, "Unrecognized filename extension "..(ext or "")
348 end
349 if not ok then
350 return false, "Failed extracting "..archive
351 end
352 return true
353end