diff options
| author | hisham <hisham@9ca3f7c1-7366-0410-b1a3-b5c78f85698c> | 2009-07-01 15:36:58 +0000 |
|---|---|---|
| committer | hisham <hisham@9ca3f7c1-7366-0410-b1a3-b5c78f85698c> | 2009-07-01 15:36:58 +0000 |
| commit | 6d045abb61a68e573cefb63b32c3bd85c7b6249e (patch) | |
| tree | 8dd124f68c7eb684d026fe713e44bddf1a56c6ae | |
| parent | abfc6b6ca8cbf492c5e8b5ff3434b92f69076125 (diff) | |
| download | luarocks-6d045abb61a68e573cefb63b32c3bd85c7b6249e.tar.gz luarocks-6d045abb61a68e573cefb63b32c3bd85c7b6249e.tar.bz2 luarocks-6d045abb61a68e573cefb63b32c3bd85c7b6249e.zip | |
progress on management of 'lib' dir
git-svn-id: http://luarocks.org/svn/luarocks/trunk@37 9ca3f7c1-7366-0410-b1a3-b5c78f85698c
| -rw-r--r-- | src/luarocks/manif.lua | 60 |
1 files changed, 50 insertions, 10 deletions
diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua index 6974dc04..74289ee5 100644 --- a/src/luarocks/manif.lua +++ b/src/luarocks/manif.lua | |||
| @@ -13,22 +13,59 @@ local fetch = require("luarocks.fetch") | |||
| 13 | local dir = require("luarocks.dir") | 13 | local dir = require("luarocks.dir") |
| 14 | local manif_core = require("luarocks.manif_core") | 14 | local manif_core = require("luarocks.manif_core") |
| 15 | 15 | ||
| 16 | local function find_module_at_file(file, modules) | ||
| 17 | for module, location in pairs(modules) do | ||
| 18 | if file == location then | ||
| 19 | return module | ||
| 20 | end | ||
| 21 | end | ||
| 22 | end | ||
| 23 | |||
| 24 | local function rename_module(file, pkgid) | ||
| 25 | local path = dir.dir_name(file) | ||
| 26 | local name = dir.base_name(file) | ||
| 27 | local pkgid = pkgid:gsub("[/.-]", "_") | ||
| 28 | return dir.path(path, pkgid.."-"..name) | ||
| 29 | end | ||
| 30 | |||
| 16 | local function make_global_lib(repo, manifest) | 31 | local function make_global_lib(repo, manifest) |
| 17 | local lib_dir = dir.path(dir.dir_name(repo), "lib") | 32 | local lib_dir = dir.path(dir.dir_name(repo), "lib") |
| 18 | fs.make_dir(lib_dir) | 33 | fs.make_dir(lib_dir) |
| 19 | for rock, modules in pairs(manifest.modules) do | 34 | for rock, modules in pairs(manifest.modules) do |
| 20 | for module, file in pairs(modules) do | 35 | for module, file in pairs(modules) do |
| 21 | local path_in_rock = dir.strip_base_dir(file:sub(#dir.path(repo, module)+2)) | 36 | if not file:match("^"..lib_dir) then |
| 22 | local module_dir = dir.dir_name(path_in_rock) | 37 | local path_in_rock = dir.strip_base_dir(file:sub(#dir.path(repo, module)+2)) |
| 23 | local dest = dir.path(lib_dir, path_in_rock) | 38 | local module_dir = dir.dir_name(path_in_rock) |
| 24 | if module_dir ~= "" then | 39 | local dest = dir.path(lib_dir, path_in_rock) |
| 25 | fs.make_dir(dir.dir_name(dest)) | 40 | if module_dir ~= "" then |
| 26 | end | 41 | fs.make_dir(dir.dir_name(dest)) |
| 27 | if not fs.exists(dest) then | 42 | end |
| 28 | fs.copy(file, dest) | 43 | if not fs.exists(dest) then |
| 29 | manifest.modules[rock][module] = dest | 44 | fs.copy(file, dest) |
| 45 | manifest.modules[rock][module] = dest | ||
| 46 | else | ||
| 47 | local current = find_module_at_file(dest, modules) | ||
| 48 | if not current then | ||
| 49 | util.warning("installed file not tracked by LuaRocks: "..dest) | ||
| 50 | else | ||
| 51 | local newname = rename_module(dest, current) | ||
| 52 | if fs.exists(newname) then | ||
| 53 | util.warning("conflict when tracking modules: "..newname.." exists.") | ||
| 54 | else | ||
| 55 | local ok, err = fs.move(dest, newname) | ||
| 56 | if ok then | ||
| 57 | manifest.modules[rock][current] = newname | ||
| 58 | fs.copy(file, dest) | ||
| 59 | manifest.modules[rock][module] = dest | ||
| 60 | else | ||
| 61 | util.warning(err) | ||
| 62 | end | ||
| 63 | end | ||
| 64 | end | ||
| 65 | -- TODO | ||
| 66 | end | ||
| 30 | else | 67 | else |
| 31 | -- TODO | 68 | print("DBG file already in place.") |
| 32 | end | 69 | end |
| 33 | end | 70 | end |
| 34 | end | 71 | end |
| @@ -262,6 +299,9 @@ function make_manifest(repo) | |||
| 262 | local manifest = { repository = {}, modules = {}, commands = {} } | 299 | local manifest = { repository = {}, modules = {}, commands = {} } |
| 263 | manif_core.manifest_cache[repo] = manifest | 300 | manif_core.manifest_cache[repo] = manifest |
| 264 | store_results(results, manifest) | 301 | store_results(results, manifest) |
| 302 | local lib_dir = dir.path(dir.dir_name(repo), "lib") | ||
| 303 | -- TODO | ||
| 304 | fs.delete(lib_dir) | ||
| 265 | make_global_lib(repo, manifest) | 305 | make_global_lib(repo, manifest) |
| 266 | return save_manifest(repo, manifest) | 306 | return save_manifest(repo, manifest) |
| 267 | end | 307 | end |
