diff options
-rw-r--r-- | lpm.c | 7 | ||||
-rw-r--r-- | lpm.lua | 29 | ||||
-rw-r--r-- | manifest.json | 4 |
3 files changed, 26 insertions, 14 deletions
@@ -424,6 +424,7 @@ static size_t lpm_curl_write_callback(char *ptr, size_t size, size_t nmemb, void static int lpm_get(lua_State* L) { + long response_code; const char* url = luaL_checkstring(L, 1); const char* path = luaL_optstring(L, 2, NULL); // curl_easy_reset(curl); @@ -440,6 +441,9 @@ static int lpm_get(lua_State* L) { return luaL_error(L, "curl error: %d", res); } fclose(file); + curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code); + if (response_code != 200) + return luaL_error(L, "curl error, non-200 response code: %d", response_code); lua_pushnil(L); lua_newtable(L); return 2; @@ -451,6 +455,9 @@ static int lpm_get(lua_State* L) { CURLcode res = curl_easy_perform(curl); if (res != CURLE_OK) return luaL_error(L, "curl error: %d", res); + curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code); + if (response_code != 200) + return luaL_error(L, "curl error, non-200 response code: %d", response_code); luaL_pushresult(&B); lua_newtable(L); } @@ -435,17 +435,22 @@ end function common.copy(src, dst) local src_stat, dst_stat = system.stat(src), system.stat(dst) if not src_stat then error("can't find " .. src) end - if dst_stat and dst_stat.type == "dir" and src_stat.type == "file" then return common.copy(src, dst .. PATHSEP .. common.basename(src)) end - local src_io, err1 = io.open(src, "rb") - if err1 then error("can't open for reading " .. src .. ": " .. err1) end - local dst_io, err2 = io.open(dst, "wb") - if err2 then error("can't open for writing " .. src .. ": " .. err2) end - while true do - local chunk = src_io:read(16*1024) - if not chunk then break end - dst_io:write(chunk) + if dst_stat and dst_stat.type == "dir" then return common.copy(src, dst .. PATHSEP .. common.basename(src)) end + if src_stat.type == "dir" then + common.mkdirp(dst) + for i, file in ipairs(system.ls(src)) do common.copy(src .. PATHSEP .. file, dst .. PATHSEP .. file) end + else + local src_io, err1 = io.open(src, "rb") + if err1 then error("can't open for reading " .. src .. ": " .. err1) end + local dst_io, err2 = io.open(dst, "wb") + if err2 then error("can't open for writing " .. src .. ": " .. err2) end + while true do + local chunk = src_io:read(16*1024) + if not chunk then break end + dst_io:write(chunk) + end + dst_io:flush() end - dst_io:flush() end @@ -632,7 +637,7 @@ function Plugin:install(installing) log_action("Installing " .. self.organization .. " plugin located at " .. self.local_path .. " to " .. self.install_path) end - if self.organization == "complex" and self.path then common.mkdirp(self.install_path) end + if self.organization == "complex" and self.path and system.stat(self.local_path).type ~= "dir" then common.mkdirp(self.install_path) end if self.url then log_action("Downloading file " .. self.url .. "...") local path = self.install_path .. (self.organization == 'complex' and (PATHSEP .. "init.lua") or "") @@ -646,7 +651,7 @@ function Plugin:install(installing) system.init(self.install_path, url) system.reset(self.install_path, branch) else - local path = self.install_path .. (self.organization == 'complex' and self.path and (PATHSEP .. "init.lua") or "") + local path = self.install_path .. (self.organization == 'complex' and self.path and system.stat(self.local_path).type ~= "dir" and (PATHSEP .. "init.lua") or "") log_action("Copying " .. self.local_path .. " to " .. path) common.copy(self.local_path, path) end diff --git a/manifest.json b/manifest.json index baf9171..c0057a4 100644 --- a/manifest.json +++ b/manifest.json @@ -7,11 +7,11 @@ "mod_version": 3, "provides": ["plugin-manager"], "files": [{ - "url": "https://github.com/adamharrison/lite-xl-plugin-manager/releases/download/0.1/lpm-x86_64-linux", + "url": "https://github.com/adamharrison/lite-xl-plugin-manager/releases/download/v0.1/lpm-x86_64-linux", "arch": "x86_64-linux", "checksum": "0019dfc4b32d63c1392aa264aed2253c1e0c2fb09216f8e2cc269bbfb8bb49b5" }, { - "url": "https://github.com/adamharrison/lite-xl-plugin-manager/releases/download/0.1/lpm-x86_64-windows", + "url": "https://github.com/adamharrison/lite-xl-plugin-manager/releases/download/v0.1/lpm-x86_64-windows", "arch": "x86_64-windows", "checksum": "440cd5dfdcbb63351c078422541631bca07b0ef659cc45d2a9ee779dadee8b43" }], |