diff options
author | Adam Harrison <adamdharrison@gmail.com> | 2024-03-22 13:48:10 -0400 |
---|---|---|
committer | Adam Harrison <adamdharrison@gmail.com> | 2024-03-22 13:48:10 -0400 |
commit | c01125c278275a37d1e95a79af2edc3beb5dd0d3 (patch) | |
tree | 54d0b39e37c79742b20e45e60f18744eecbfc2eb /src/lpm.lua | |
parent | fd97818a70652471b33b577e2d8ea855e770d533 (diff) | |
download | lite-xl-plugin-manager-c01125c278275a37d1e95a79af2edc3beb5dd0d3.tar.gz lite-xl-plugin-manager-c01125c278275a37d1e95a79af2edc3beb5dd0d3.zip |
Should fix #100
Diffstat (limited to 'src/lpm.lua')
-rw-r--r-- | src/lpm.lua | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/lpm.lua b/src/lpm.lua index cb95b1a..645e986 100644 --- a/src/lpm.lua +++ b/src/lpm.lua @@ -595,31 +595,33 @@ end function common.get(source, options) options = options or {} + if not options.depth then options.depth = {} end + table.insert(options.depth, source) local target, checksum, callback, depth = options.target, options.checksum or "SKIP", options.callback, options.depth if not source then error("requires url") end - if (depth or 0) > 10 then error("too many redirects") end + if #depth > 10 then error("too many redirects") end local _, _, protocol, hostname, port, rest = source:find("^(https?)://([^:/?]+):?(%d*)(.*)$") - log.progress_action("Downloading " .. source:sub(1, 100) .. "...") + if #depth == 1 then log.progress_action("Downloading " .. options.depth[1]:sub(1, 100) .. "...") end 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 rest or rest == "" then rest = "/" end local res, headers if checksum == "SKIP" and not target then res, headers = system.get(protocol, hostname, port, rest, target, callback) - if headers.location then return common.get(headers.location, common.merge(options, { depth = (depth or 0) + 1 })) end + if headers.location then return common.get(headers.location, common.merge(options, { })) end return res end local cache_dir = checksum == "SKIP" and TMPDIR or (options.cache or CACHEDIR) if not system.stat(cache_dir .. PATHSEP .. "files") then common.mkdirp(cache_dir .. PATHSEP .. "files") end - local cache_path = cache_dir .. PATHSEP .. "files" .. PATHSEP .. system.hash(checksum .. source) + local cache_path = cache_dir .. PATHSEP .. "files" .. PATHSEP .. system.hash(checksum .. options.depth[1]) if checksum ~= "SKIP" and system.stat(cache_path) and system.hash(cache_path, "file") ~= checksum then common.rmrf(cache_path) end local res if not system.stat(cache_path) then res, headers = system.get(protocol, hostname, port, rest, cache_path .. ".part", callback) - if headers.location then return common.get(headers.location, common.merge(options, { depth = (depth or 0) + 1 })) end + if headers.location then return common.get(headers.location, common.merge(options, { })) end if checksum ~= "SKIP" and system.hash(cache_path .. ".part", "file") ~= checksum then common.rmrf(cache_path .. ".part") - log.fatal_warning("checksum doesn't match for " .. source) + log.fatal_warning("checksum doesn't match for " .. options.depth[1]) end common.rename(cache_path .. ".part", cache_path) end |