aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2010-12-14 12:12:26 -0200
committerHisham Muhammad <hisham@gobolinux.org>2010-12-14 12:12:26 -0200
commitb2f4e356b6ede8860b22501aa4ee2578ec9a1a03 (patch)
tree65559b5e0437130fd34a6e15b7294a9bd88a14f2
parent799736f057658d05446c722b4e157d48aff86a2e (diff)
downloadluarocks-b2f4e356b6ede8860b22501aa4ee2578ec9a1a03.tar.gz
luarocks-b2f4e356b6ede8860b22501aa4ee2578ec9a1a03.tar.bz2
luarocks-b2f4e356b6ede8860b22501aa4ee2578ec9a1a03.zip
Fix sorting and saving of persisted manifest table.
-rw-r--r--src/luarocks/manif.lua4
-rw-r--r--src/luarocks/manif_core.lua4
-rw-r--r--src/luarocks/persist.lua10
-rw-r--r--src/luarocks/util.lua16
4 files changed, 22 insertions, 12 deletions
diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua
index c677a22c..a7211d70 100644
--- a/src/luarocks/manif.lua
+++ b/src/luarocks/manif.lua
@@ -304,9 +304,9 @@ local function find_providers(file, root)
304 assert(type(file) == "string") 304 assert(type(file) == "string")
305 root = root or cfg.root_dir 305 root = root or cfg.root_dir
306 306
307 local manifest = manif_core.load_local_manifest(path.rocks_dir(root)) 307 local manifest, err = manif_core.load_local_manifest(path.rocks_dir(root))
308 if not manifest then 308 if not manifest then
309 return nil, "manifest file is missing. Corrupted local rocks tree?" 309 return nil, err .. " -- corrupted local rocks tree?"
310 end 310 end
311 local deploy_bin = path.deploy_bin_dir(root) 311 local deploy_bin = path.deploy_bin_dir(root)
312 local deploy_lua = path.deploy_lua_dir(root) 312 local deploy_lua = path.deploy_lua_dir(root)
diff --git a/src/luarocks/manif_core.lua b/src/luarocks/manif_core.lua
index d1eb4ebb..2e1a9518 100644
--- a/src/luarocks/manif_core.lua
+++ b/src/luarocks/manif_core.lua
@@ -16,9 +16,9 @@ manifest_cache = {}
16-- @param file string: The local filename of the manifest file. 16-- @param file string: The local filename of the manifest file.
17-- @param repo_url string: The repository identifier. 17-- @param repo_url string: The repository identifier.
18function manifest_loader(file, repo_url, quick) 18function manifest_loader(file, repo_url, quick)
19 local manifest = persist.load_into_table(file) 19 local manifest, err = persist.load_into_table(file)
20 if not manifest then 20 if not manifest then
21 return nil, "Failed loading manifest for "..repo_url 21 return nil, "Failed loading manifest for "..repo_url..": "..err
22 end 22 end
23 if not quick then 23 if not quick then
24 local ok, err = type_check.type_check_manifest(manifest) 24 local ok, err = type_check.type_check_manifest(manifest)
diff --git a/src/luarocks/persist.lua b/src/luarocks/persist.lua
index d74a805e..c809b51c 100644
--- a/src/luarocks/persist.lua
+++ b/src/luarocks/persist.lua
@@ -28,10 +28,6 @@ function load_into_table(filename, tbl)
28 return result 28 return result
29end 29end
30 30
31local function string_sort(a,b)
32 return tostring(a) < tostring(b)
33end
34
35--- Write a table as Lua code representing a table to disk 31--- Write a table as Lua code representing a table to disk
36-- (that is, in curly brackets notation). 32-- (that is, in curly brackets notation).
37-- This function handles only numbers, strings and tables 33-- This function handles only numbers, strings and tables
@@ -43,7 +39,7 @@ local function write_table(out, tbl, level)
43 local sep = "\n" 39 local sep = "\n"
44 local indent = true 40 local indent = true
45 local i = 1 41 local i = 1
46 for k, v in util.sortedpairs(tbl, string_sort) do 42 for k, v in util.sortedpairs(tbl) do
47 out:write(sep) 43 out:write(sep)
48 if indent then 44 if indent then
49 for n = 1,level do out:write(" ") end 45 for n = 1,level do out:write(" ") end
@@ -52,7 +48,7 @@ local function write_table(out, tbl, level)
52 indent = true 48 indent = true
53 if type(k) == "number" then 49 if type(k) == "number" then
54 if k ~= i then 50 if k ~= i then
55 out:write(tostring(k).."=") 51 out:write('['..tostring(k).."]=")
56 else 52 else
57 i = i + 1 53 i = i + 1
58 end 54 end
@@ -95,7 +91,7 @@ function save_from_table(filename, tbl)
95 if not out then 91 if not out then
96 return nil, "Cannot create file at "..filename 92 return nil, "Cannot create file at "..filename
97 end 93 end
98 for k, v in util.sortedpairs(tbl, string_sort) do 94 for k, v in util.sortedpairs(tbl) do
99 out:write(k.." = ") 95 out:write(k.." = ")
100 write_table(out, v, 1) 96 write_table(out, v, 1)
101 out:write("\n") 97 out:write("\n")
diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua
index 10fc1e36..e0c01421 100644
--- a/src/luarocks/util.lua
+++ b/src/luarocks/util.lua
@@ -216,6 +216,20 @@ function keys(tbl)
216 return ks 216 return ks
217end 217end
218 218
219local function default_sort(a, b)
220 local ta = type(a)
221 local tb = type(b)
222 if ta == "number" and tb == "number" then
223 return a < b
224 elseif ta == "number" then
225 return true
226 elseif tb == "number" then
227 return false
228 else
229 return tostring(a) < tostring(b)
230 end
231end
232
219-- The iterator function used internally by util.sortedpairs. 233-- The iterator function used internally by util.sortedpairs.
220-- @param tbl table: The table to be iterated. 234-- @param tbl table: The table to be iterated.
221-- @param sort_function function or nil: An optional comparison function 235-- @param sort_function function or nil: An optional comparison function
@@ -223,7 +237,7 @@ end
223-- @see sortedpairs 237-- @see sortedpairs
224local function sortedpairs_iterator(tbl, sort_function) 238local function sortedpairs_iterator(tbl, sort_function)
225 local ks = keys(tbl) 239 local ks = keys(tbl)
226 table.sort(ks, sort_function) 240 table.sort(ks, sort_function or default_sort)
227 for _, k in ipairs(ks) do 241 for _, k in ipairs(ks) do
228 coroutine.yield(k, tbl[k]) 242 coroutine.yield(k, tbl[k])
229 end 243 end