From 9f59a5c272af8d283ecc54b3578daaf64bd8612e Mon Sep 17 00:00:00 2001 From: hisham Date: Fri, 14 Aug 2009 18:32:39 +0000 Subject: improvements to 'add' function git-svn-id: http://luarocks.org/svn/luarocks/trunk@47 9ca3f7c1-7366-0410-b1a3-b5c78f85698c --- src/luarocks/add.lua | 42 ++++++++++++++++++++++++++++++++---------- src/luarocks/cfg.lua | 2 ++ src/luarocks/manif.lua | 9 +++++---- 3 files changed, 39 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/luarocks/add.lua b/src/luarocks/add.lua index 5671b84e..96099d36 100644 --- a/src/luarocks/add.lua +++ b/src/luarocks/add.lua @@ -19,10 +19,8 @@ If not given, the default server set in the upload_server variable from the configuration file is used instead. ]] -local function add_file_to_server(rockfile, server) +local function split_server_url(server, user, password) local protocol, server_path = dir.split_url(server) - local user = cfg.upload_user - local password = cfg.upload_password if server_path:match("@") then local credentials credentials, server_path = server_path:match("([^@]*)@(.*)") @@ -32,14 +30,18 @@ local function add_file_to_server(rockfile, server) user = credentials end end - if not fs.exists(rockfile) then - return nil, "Could not find "..rockfile - end - local rockfile = fs.absolute_name(rockfile) local local_cache if cfg.local_cache then local_cache = cfg.local_cache .. "/" .. server_path end + return local_cache, protocol, server_path, user, password +end + +local function refresh_local_cache(server, user, password) + local local_cache, protocol, server_path, user, password = split_server_url(server, user, password) + + fs.make_dir(cfg.local_cache) + local tmp_cache = false if not local_cache then local_cache = fs.make_temp_dir("local_cache") @@ -57,10 +59,29 @@ local function add_file_to_server(rockfile, server) if password then login_info = login_info .. " --password="..password end fs.execute("wget -q -m -nd "..protocol.."://"..server_path..login_info) - print("Copying file...") + return local_cache, protocol, server_path, user, password +end + +local function add_file_to_server(refresh, rockfile, server) + if not fs.exists(rockfile) then + return nil, "Could not find "..rockfile + end + + local local_cache, protocol, server_path, user, password + if refresh then + local_cache, protocol, server_path, user, password = refresh_local_cache(server, cfg.upload_user, cfg.upload_password) + else + local_cache, protocol, server_path, user, password = split_server_url(server, cfg.upload_user, cfg.upload_password) + end + fs.change_dir(local_cache) + + local rockfile = fs.absolute_name(rockfile) + print("Copying file "..rockfile.." to "..local_cache.."...") fs.copy(rockfile, local_cache) - print("Updating manifest and index.html...") + + print("Updating manifest...") manif.make_manifest(local_cache) + print("Updating index.html...") manif.make_index(local_cache) local login_info = "" @@ -70,6 +91,7 @@ local function add_file_to_server(rockfile, server) server_path = server_path .. "/" end fs.execute("curl "..login_info.." -T '{manifest,index.html,"..dir.base_name(rockfile).."}' "..protocol.."://"..server_path) + return true end @@ -86,6 +108,6 @@ function run(...) if cfg.upload_aliases then server = cfg.upload_aliases[server] or server end - return add_file_to_server(file, server) + return add_file_to_server(not flags["no-refresh"], file, server) end diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index d4bcbfb6..ddcfac9d 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua @@ -168,6 +168,7 @@ if detected.windows then lib = { "?.dll" }, include = { "?.h" } } + defaults.local_cache = home.."/cache/luarocks" end if detected.unix then @@ -195,6 +196,7 @@ if detected.unix then lib = { "lib?.so" }, include = { "?.h" } } + defaults.local_cache = home.."/.cache/luarocks" end if detected.cygwin then diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua index 03512584..2343489b 100644 --- a/src/luarocks/manif.lua +++ b/src/luarocks/manif.lua @@ -310,16 +310,16 @@ function make_manifest(repo) local manifest = { repository = {}, modules = {}, commands = {} } manif_core.manifest_cache[repo] = manifest - print(util.show_table(results, "results")) - print(util.show_table(manifest, "manifest")) + --print(util.show_table(results, "results")) + --print(util.show_table(manifest, "manifest")) store_results(results, manifest) - print(util.show_table(manifest, "manifest after store")) + --print(util.show_table(manifest, "manifest after store")) update_global_lib(repo, manifest) - print(util.show_table(manifest, "manifest after update")) + --print(util.show_table(manifest, "manifest after update")) return save_manifest(repo, manifest) end @@ -405,6 +405,7 @@ function make_index(repo) end local manifest = load_manifest(repo) local out = io.open(dir.path(repo, "index.html"), "w") + out:write(index_header) for package, version_list in util.sortedpairs(manifest.repository) do local latest_rockspec = nil -- cgit v1.2.3-55-g6feb