aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorXpol Wan <xpolife@gmail.com>2015-03-18 15:38:52 +0800
committerXpol Wan <xpolife@gmail.com>2015-03-18 15:38:52 +0800
commit90586f6616b2b1c7cea67eaa64a8c79e1591a921 (patch)
tree342022bcd96c1400e171fb5171ff55f2a3332b60 /src
parentbdf218bfa94abf353d662ee92674ca22a33f8f25 (diff)
parent88a903a50bd0e581b8886004402d41f44d2255e1 (diff)
downloadluarocks-90586f6616b2b1c7cea67eaa64a8c79e1591a921.tar.gz
luarocks-90586f6616b2b1c7cea67eaa64a8c79e1591a921.tar.bz2
luarocks-90586f6616b2b1c7cea67eaa64a8c79e1591a921.zip
Merge branch 'master' of https://github.com/keplerproject/luarocks
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/upload/api.lua17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/luarocks/upload/api.lua b/src/luarocks/upload/api.lua
index fd476968..6dfb98df 100644
--- a/src/luarocks/upload/api.lua
+++ b/src/luarocks/upload/api.lua
@@ -119,6 +119,11 @@ end
119local ltn12_ok, ltn12 = pcall(require, "ltn12") 119local ltn12_ok, ltn12 = pcall(require, "ltn12")
120if not ltn12_ok then -- If not using LuaSocket and/or LuaSec... 120if not ltn12_ok then -- If not using LuaSocket and/or LuaSec...
121 121
122local function redact_api_url(url)
123 url = tostring(url)
124 return (url:gsub(".*/api/[^/]+/[^/]+", "")) or ""
125end
126
122function Api:request(url, params, post_params) 127function Api:request(url, params, post_params)
123 local vars = cfg.variables 128 local vars = cfg.variables
124 local json_ok, json = require_json() 129 local json_ok, json = require_json()
@@ -157,26 +162,26 @@ function Api:request(url, params, post_params)
157 end 162 end
158 local ok = fs.execute_string(curl_cmd..fs.Q(url).." -o "..fs.Q(tmpfile)) 163 local ok = fs.execute_string(curl_cmd..fs.Q(url).." -o "..fs.Q(tmpfile))
159 if not ok then 164 if not ok then
160 return nil, "API failure: " .. tostring(url) 165 return nil, "API failure: " .. redact_api_url(url)
161 end 166 end
162 else 167 else
163 local ok, err = fs.download(url, tmpfile) 168 local ok, err = fs.download(url, tmpfile)
164 if not ok then 169 if not ok then
165 return nil, "API failure: " .. tostring(err) .. " - " .. tostring(url) 170 return nil, "API failure: " .. tostring(err) .. " - " .. redact_api_url(url)
166 end 171 end
167 end 172 end
168 173
169 local tmpfd = io.open(tmpfile) 174 local tmpfd = io.open(tmpfile)
170 if not tmpfd then 175 if not tmpfd then
171 os.remove(tmpfile) 176 os.remove(tmpfile)
172 return nil, "API failure reading temporary file - " .. tostring(url) 177 return nil, "API failure reading temporary file - " .. redact_api_url(url)
173 end 178 end
174 out = tmpfd:read("*a") 179 out = tmpfd:read("*a")
175 tmpfd:close() 180 tmpfd:close()
176 os.remove(tmpfile) 181 os.remove(tmpfile)
177 182
178 if self.debug then 183 if self.debug then
179 util.printout("[" .. tostring(method) .. " via curl] " .. tostring(url) .. " ... ") 184 util.printout("[" .. tostring(method) .. " via curl] " .. redact_api_url(url) .. " ... ")
180 end 185 end
181 186
182 return json.decode(out) 187 return json.decode(out)
@@ -229,7 +234,7 @@ function Api:request(url, params, post_params)
229 end 234 end
230 local method = post_params and "POST" or "GET" 235 local method = post_params and "POST" or "GET"
231 if self.debug then 236 if self.debug then
232 util.printout("[" .. tostring(method) .. " via "..via.."] " .. tostring(url) .. " ... ") 237 util.printout("[" .. tostring(method) .. " via "..via.."] " .. redact_api_url(url) .. " ... ")
233 end 238 end
234 local out = {} 239 local out = {}
235 local _, status = http.request({ 240 local _, status = http.request({
@@ -243,7 +248,7 @@ function Api:request(url, params, post_params)
243 util.printout(tostring(status)) 248 util.printout(tostring(status))
244 end 249 end
245 if status ~= 200 then 250 if status ~= 200 then
246 return nil, "API returned " .. tostring(status) .. " - " .. tostring(url) 251 return nil, "API returned " .. tostring(status) .. " - " .. redact_api_url(url)
247 end 252 end
248 return json.decode(table.concat(out)) 253 return json.decode(table.concat(out))
249end 254end