aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam Harrison <adamdharrison@gmail.com>2024-03-03 14:48:16 -0500
committerAdam Harrison <adamdharrison@gmail.com>2024-03-03 14:48:16 -0500
commit883f345e31af4a2ad68a1c2da4c2fcc7c4a8ce3b (patch)
tree6ce30a141c524432605b81c6f77d80b218fb904c /src
parent4127f7c9b4b82ac68c3e545018e49b4952e4774b (diff)
downloadlite-xl-plugin-manager-883f345e31af4a2ad68a1c2da4c2fcc7c4a8ce3b.tar.gz
lite-xl-plugin-manager-883f345e31af4a2ad68a1c2da4c2fcc7c4a8ce3b.zip
Fixed things up.
Diffstat (limited to 'src')
-rw-r--r--src/lpm.lua20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/lpm.lua b/src/lpm.lua
index 5a83a36..4cbb817 100644
--- a/src/lpm.lua
+++ b/src/lpm.lua
@@ -1992,20 +1992,24 @@ local function lpm_self_upgrade(release)
local release_url = release and release:find("^https://") and release or (DEFAULT_RELEASE_URL:gsub("%%r", release))
local stat = system.stat(path)
if not stat then error("can't find lpm at " .. path) end
- local target = SYSTMPDIR .. PATHSEP .. "lpm.upgrade"
- common.rmrf(target)
- local status, err = pcall(common.get, release_url, { cache = SYSTMPDIR, target = target, callback = write_progress_bar })
+ local new_temporary_file = SYSTMPDIR .. PATHSEP .. "lpm.upgrade"
+ local old_temporary_file = SYSTMPDIR .. PATHSEP .. "lpm.backup"
+ common.rmrf(new_temporary_file)
+ common.rmrf(old_temporary_file)
+ local status, err = pcall(common.get, release_url, { cache = SYSTMPDIR, target = new_temporary_file, callback = write_progress_bar })
if not status then error("can't find release for lpm at " .. release_url .. (VERBOSE and (": " .. err) or "")) end
- if common.is_path_different(target, path) then
- status, err = pcall(common.rename, path, path .. ".bak")
+ if common.is_path_different(new_temporary_file, path) then
+ status, err = pcall(common.rename, path, old_temporary_file)
if not status then error("can't move lpm executable; do you need to " .. (PLATFORM == "windows" and "run as administrator" or "be root") .. "?" .. (VERBOSE and ": " .. err or "")) end
- common.rename(target, path)
+ common.rename(new_temporary_file, path)
system.chmod(path, stat.mode)
- common.rmrf(path .. ".bak")
+ if PLATFORM ~= "windows" then -- because we can't delete the running executbale on windows
+ common.rmrf(old_temporary_file)
+ end
log_action("Upgraded lpm to " .. release .. ".")
else
log_warning("aborting upgrade; remote executable is identical to current")
- common.rmrf(target)
+ common.rmrf(new_temporary_file)
end
end