aboutsummaryrefslogtreecommitdiff
path: root/src/lpm.lua
diff options
context:
space:
mode:
authorAdam Harrison <adamdharrison@gmail.com>2022-11-30 00:10:35 -0500
committerAdam Harrison <adamdharrison@gmail.com>2022-11-30 00:10:35 -0500
commit5788acb842cb828471120fd512c0c43a90048a6b (patch)
tree3087c06e92d0e031c72d5e39705e1bd0dd6e06a6 /src/lpm.lua
parente038c8cc6818dab3f8ccd4d78ae8797d591cc13f (diff)
downloadlite-xl-plugin-manager-5788acb842cb828471120fd512c0c43a90048a6b.tar.gz
lite-xl-plugin-manager-5788acb842cb828471120fd512c0c43a90048a6b.zip
Added in redirect support.
Diffstat (limited to 'src/lpm.lua')
-rw-r--r--src/lpm.lua10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/lpm.lua b/src/lpm.lua
index b38a231..034bfdc 100644
--- a/src/lpm.lua
+++ b/src/lpm.lua
@@ -458,16 +458,22 @@ local function prompt(message)
return not response:find("%S") or response:find("^%s*[yY]%s*$")
end
+
function common.get(source, target, checksum)
if not source then error("requires url") end
local _, _, protocol, hostname, port, rest = source:find("^(https?)://([^:/?]+):?(%d*)(.*)$")
if not protocol then error("malfomed url " .. source) end
if not port or port == "" then port = protocol == "https" and 443 or 80 end
- if not checksum then return system.get(protocol, hostname, port, rest, target) end
+ if not checksum then
+ local res, headers = system.get(protocol, hostname, port, rest, target)
+ if headers.location then return common.get(headers.location, target, checksum) end
+ return res
+ end
if not system.stat(CACHEDIR .. PATHSEP .. "files") then common.mkdirp(CACHEDIR .. PATHSEP .. "files") end
local cache_path = CACHEDIR .. PATHSEP .. "files" .. PATHSEP .. checksum
if not system.stat(cache_path) then
- system.get(source, cache_path)
+ local res, headers = system.get(source, cache_path)
+ if headers.location then return common.get(headers.location, target, checksum) end
if checksum ~= "SKIP" and system.hash(cache_path, "file") ~= checksum then fatal_warning("checksum doesn't match for " .. source) end
end
common.copy(cache_path, target)