From ff226c67e35c9b451abb38382774fccf947727f8 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 20 Sep 2013 22:45:56 -0300 Subject: Use zipped manifests. Makes LR a bit faster! --- src/luarocks/add.lua | 9 +++++-- src/luarocks/fs/unix/tools.lua | 2 +- src/luarocks/index.lua | 19 +++++++++++---- src/luarocks/manif.lua | 53 ++++++++++++++++++++++++++++++------------ src/luarocks/util.lua | 9 +++++++ 5 files changed, 69 insertions(+), 23 deletions(-) diff --git a/src/luarocks/add.lua b/src/luarocks/add.lua index 54991291..831d3b92 100644 --- a/src/luarocks/add.lua +++ b/src/luarocks/add.lua @@ -68,6 +68,9 @@ local function add_files_to_server(refresh, rockfiles, server, upload_server) util.printout("Updating manifest...") manif.make_manifest(local_cache, "one", true) + + manif.zip_manifests() + util.printout("Updating index.html...") index.make_index(local_cache) @@ -80,8 +83,10 @@ local function add_files_to_server(refresh, rockfiles, server, upload_server) table.insert(files, "index.html") table.insert(files, "manifest") - table.insert(files, "manifest-5.1") - table.insert(files, "manifest-5.2") + for ver in util.lua_versions() do + table.insert(files, "manifest-"..ver) + table.insert(files, "manifest-"..ver..".zip") + end -- TODO abstract away explicit 'curl' call diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua index 64992b91..9e4acf73 100644 --- a/src/luarocks/fs/unix/tools.lua +++ b/src/luarocks/fs/unix/tools.lua @@ -206,7 +206,7 @@ end -- @return boolean: true on success, false on failure. function unzip(zipfile) assert(zipfile) - return fs.execute(vars.UNZIP, zipfile) + return fs.execute_string(fs.quiet(vars.UNZIP.." "..fs.Q(zipfile))) end --- Test is file/directory exists diff --git a/src/luarocks/index.lua b/src/luarocks/index.lua index 6147a4d2..e0785d9c 100644 --- a/src/luarocks/index.lua +++ b/src/luarocks/index.lua @@ -66,7 +66,7 @@ Lua modules available from this location for use with ]] -local index_package_start = [[ +local index_package_begin = [[

$package - $summary

$detailed
@@ -81,10 +81,15 @@ local index_package_end = [[ ]] -local index_footer = [[ +local index_footer_begin = [[

-manifest fileLua 5.1 manifest fileLua 5.2 manifest file +manifest file +]] +local index_manifest_ver = [[ +• Lua $VER manifest file (zip) +]] +local index_footer_end = [[

@@ -128,7 +133,7 @@ function make_index(repo) out:write(index_header) for package, version_list in util.sortedpairs(manifest.repository) do local latest_rockspec = nil - local output = index_package_start + local output = index_package_begin for version, data in util.sortedpairs(version_list, deps.compare_versions) do local versions = {} output = output..version..': ' @@ -170,6 +175,10 @@ function make_index(repo) end out:write(output) end - out:write(index_footer) + out:write(index_footer_begin) + for ver in util.lua_versions() do + out:write((index_manifest_ver:gsub("$VER", ver))) + end + out:write(index_footer_end) out:close() end diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua index d0bd5e04..03377d52 100644 --- a/src/luarocks/manif.lua +++ b/src/luarocks/manif.lua @@ -103,26 +103,40 @@ function load_manifest(repo_url) if manif_core.manifest_cache[repo_url] then return manif_core.manifest_cache[repo_url] end - - local vmanifest = "manifest-"..cfg.lua_version - - local protocol, pathname = dir.split_url(repo_url) + + local filenames = { + "manifest-"..cfg.lua_version..".zip", + "manifest-"..cfg.lua_version, + "manifest", + } + + local protocol, repodir = dir.split_url(repo_url) + local pathname if protocol == "file" then - local file = dir.path(pathname, vmanifest) - if fs.exists(file) then - pathname = file - else - pathname = dir.path(pathname, "manifest") + for _, filename in ipairs(filenames) do + pathname = dir.path(repodir, filename) + if fs.exists(pathname) then + break + end end else - local file, err = fetch_manifest_from(repo_url, vmanifest) - if not file then - file, err = fetch_manifest_from(repo_url, "manifest") + local err + for _, filename in ipairs(filenames) do + pathname, err = fetch_manifest_from(repo_url, filename) + if pathname then + break + end end - if not file then + if not pathname then return nil, err end - pathname = file + end + if pathname:match(".*%.zip$") then + local dir = dir.dir_name(pathname) + fs.change_dir(dir) + fs.unzip(pathname) + fs.pop_dir() + pathname = pathname:match("(.*)%.zip$") end return manif_core.manifest_loader(pathname, repo_url) end @@ -343,7 +357,7 @@ function make_manifest(repo, deps_mode, versioned) if not ok then return nil, err end if versioned then - for _, luaver in ipairs({"5.1", "5.2"}) do + for luaver in util.lua_versions() do local vmanifest = { repository = {}, modules = {}, commands = {} } local ok, err = store_results(results, vmanifest, deps_mode, repo, luaver, cache) save_table(repo, "manifest-"..luaver, vmanifest) @@ -397,6 +411,15 @@ function update_manifest(name, version, repo, deps_mode) return save_table(repo, "manifest", manifest) end +function zip_manifests() + for ver in util.lua_versions() do + local file = "manifest-"..ver + local zip = file..".zip" + fs.delete(dir.path(fs.current_dir(), zip)) + fs.zip(zip, file) + end +end + local function find_providers(file, root) assert(type(file) == "string") root = root or cfg.root_dir diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index ba20acfa..e3260359 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua @@ -319,6 +319,15 @@ function sortedpairs(tbl, sort_function) return coroutine.wrap(function() sortedpairs_iterator(tbl, sort_function) end) end +function lua_versions() + local versions = { "5.1", "5.2" } + local i = 0 + return function() + i = i + 1 + return versions[i] + end +end + function starts_with(s, prefix) return s:sub(1,#prefix) == prefix end -- cgit v1.2.3-55-g6feb