aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhisham <hisham@9ca3f7c1-7366-0410-b1a3-b5c78f85698c>2009-08-14 18:32:39 +0000
committerhisham <hisham@9ca3f7c1-7366-0410-b1a3-b5c78f85698c>2009-08-14 18:32:39 +0000
commit9f59a5c272af8d283ecc54b3578daaf64bd8612e (patch)
tree37836c58d9521beccc9c404cb1dd481db07430c7 /src
parentbf12f5f325f80a9b59e127f0e07689d7e9fe4e5e (diff)
downloadluarocks-9f59a5c272af8d283ecc54b3578daaf64bd8612e.tar.gz
luarocks-9f59a5c272af8d283ecc54b3578daaf64bd8612e.tar.bz2
luarocks-9f59a5c272af8d283ecc54b3578daaf64bd8612e.zip
improvements to 'add' function
git-svn-id: http://luarocks.org/svn/luarocks/trunk@47 9ca3f7c1-7366-0410-b1a3-b5c78f85698c
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/add.lua42
-rw-r--r--src/luarocks/cfg.lua2
-rw-r--r--src/luarocks/manif.lua9
3 files changed, 39 insertions, 14 deletions
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
19from the configuration file is used instead. 19from the configuration file is used instead.
20]] 20]]
21 21
22local function add_file_to_server(rockfile, server) 22local function split_server_url(server, user, password)
23 local protocol, server_path = dir.split_url(server) 23 local protocol, server_path = dir.split_url(server)
24 local user = cfg.upload_user
25 local password = cfg.upload_password
26 if server_path:match("@") then 24 if server_path:match("@") then
27 local credentials 25 local credentials
28 credentials, server_path = server_path:match("([^@]*)@(.*)") 26 credentials, server_path = server_path:match("([^@]*)@(.*)")
@@ -32,14 +30,18 @@ local function add_file_to_server(rockfile, server)
32 user = credentials 30 user = credentials
33 end 31 end
34 end 32 end
35 if not fs.exists(rockfile) then
36 return nil, "Could not find "..rockfile
37 end
38 local rockfile = fs.absolute_name(rockfile)
39 local local_cache 33 local local_cache
40 if cfg.local_cache then 34 if cfg.local_cache then
41 local_cache = cfg.local_cache .. "/" .. server_path 35 local_cache = cfg.local_cache .. "/" .. server_path
42 end 36 end
37 return local_cache, protocol, server_path, user, password
38end
39
40local function refresh_local_cache(server, user, password)
41 local local_cache, protocol, server_path, user, password = split_server_url(server, user, password)
42
43 fs.make_dir(cfg.local_cache)
44
43 local tmp_cache = false 45 local tmp_cache = false
44 if not local_cache then 46 if not local_cache then
45 local_cache = fs.make_temp_dir("local_cache") 47 local_cache = fs.make_temp_dir("local_cache")
@@ -57,10 +59,29 @@ local function add_file_to_server(rockfile, server)
57 if password then login_info = login_info .. " --password="..password end 59 if password then login_info = login_info .. " --password="..password end
58 60
59 fs.execute("wget -q -m -nd "..protocol.."://"..server_path..login_info) 61 fs.execute("wget -q -m -nd "..protocol.."://"..server_path..login_info)
60 print("Copying file...") 62 return local_cache, protocol, server_path, user, password
63end
64
65local function add_file_to_server(refresh, rockfile, server)
66 if not fs.exists(rockfile) then
67 return nil, "Could not find "..rockfile
68 end
69
70 local local_cache, protocol, server_path, user, password
71 if refresh then
72 local_cache, protocol, server_path, user, password = refresh_local_cache(server, cfg.upload_user, cfg.upload_password)
73 else
74 local_cache, protocol, server_path, user, password = split_server_url(server, cfg.upload_user, cfg.upload_password)
75 end
76 fs.change_dir(local_cache)
77
78 local rockfile = fs.absolute_name(rockfile)
79 print("Copying file "..rockfile.." to "..local_cache.."...")
61 fs.copy(rockfile, local_cache) 80 fs.copy(rockfile, local_cache)
62 print("Updating manifest and index.html...") 81
82 print("Updating manifest...")
63 manif.make_manifest(local_cache) 83 manif.make_manifest(local_cache)
84 print("Updating index.html...")
64 manif.make_index(local_cache) 85 manif.make_index(local_cache)
65 86
66 local login_info = "" 87 local login_info = ""
@@ -70,6 +91,7 @@ local function add_file_to_server(rockfile, server)
70 server_path = server_path .. "/" 91 server_path = server_path .. "/"
71 end 92 end
72 fs.execute("curl "..login_info.." -T '{manifest,index.html,"..dir.base_name(rockfile).."}' "..protocol.."://"..server_path) 93 fs.execute("curl "..login_info.." -T '{manifest,index.html,"..dir.base_name(rockfile).."}' "..protocol.."://"..server_path)
94
73 return true 95 return true
74end 96end
75 97
@@ -86,6 +108,6 @@ function run(...)
86 if cfg.upload_aliases then 108 if cfg.upload_aliases then
87 server = cfg.upload_aliases[server] or server 109 server = cfg.upload_aliases[server] or server
88 end 110 end
89 return add_file_to_server(file, server) 111 return add_file_to_server(not flags["no-refresh"], file, server)
90end 112end
91 113
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
168 lib = { "?.dll" }, 168 lib = { "?.dll" },
169 include = { "?.h" } 169 include = { "?.h" }
170 } 170 }
171 defaults.local_cache = home.."/cache/luarocks"
171end 172end
172 173
173if detected.unix then 174if detected.unix then
@@ -195,6 +196,7 @@ if detected.unix then
195 lib = { "lib?.so" }, 196 lib = { "lib?.so" },
196 include = { "?.h" } 197 include = { "?.h" }
197 } 198 }
199 defaults.local_cache = home.."/.cache/luarocks"
198end 200end
199 201
200if detected.cygwin then 202if 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)
310 local manifest = { repository = {}, modules = {}, commands = {} } 310 local manifest = { repository = {}, modules = {}, commands = {} }
311 manif_core.manifest_cache[repo] = manifest 311 manif_core.manifest_cache[repo] = manifest
312 312
313 print(util.show_table(results, "results")) 313 --print(util.show_table(results, "results"))
314 print(util.show_table(manifest, "manifest")) 314 --print(util.show_table(manifest, "manifest"))
315 315
316 store_results(results, manifest) 316 store_results(results, manifest)
317 317
318 print(util.show_table(manifest, "manifest after store")) 318 --print(util.show_table(manifest, "manifest after store"))
319 319
320 update_global_lib(repo, manifest) 320 update_global_lib(repo, manifest)
321 321
322 print(util.show_table(manifest, "manifest after update")) 322 --print(util.show_table(manifest, "manifest after update"))
323 323
324 return save_manifest(repo, manifest) 324 return save_manifest(repo, manifest)
325end 325end
@@ -405,6 +405,7 @@ function make_index(repo)
405 end 405 end
406 local manifest = load_manifest(repo) 406 local manifest = load_manifest(repo)
407 local out = io.open(dir.path(repo, "index.html"), "w") 407 local out = io.open(dir.path(repo, "index.html"), "w")
408
408 out:write(index_header) 409 out:write(index_header)
409 for package, version_list in util.sortedpairs(manifest.repository) do 410 for package, version_list in util.sortedpairs(manifest.repository) do
410 local latest_rockspec = nil 411 local latest_rockspec = nil