aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Harrison <adamdharrison@gmail.com>2023-06-19 18:40:09 -0400
committerAdam Harrison <adamdharrison@gmail.com>2023-06-19 18:40:09 -0400
commitdade9f4849438cf1a62db6ac273934872083c233 (patch)
tree64dad26552fe39c90c94b79b9b3c1fd95d42f1e7
parent2eabb4ccab83ce051bd2be53877cc0ad9d295645 (diff)
downloadlite-xl-plugin-manager-dade9f4849438cf1a62db6ac273934872083c233.tar.gz
lite-xl-plugin-manager-dade9f4849438cf1a62db6ac273934872083c233.zip
Colorized some more messages. Added in a tmp file for repository fetching, so that we do not have an inconsistent state after an error.
-rw-r--r--src/lpm.lua39
1 files changed, 22 insertions, 17 deletions
diff --git a/src/lpm.lua b/src/lpm.lua
index 6aefc9a..f3b69f4 100644
--- a/src/lpm.lua
+++ b/src/lpm.lua
@@ -1107,17 +1107,18 @@ end
-- useds to fetch things from a generic place
function Repository:fetch()
if self:is_local() then return self end
- local path
+ local path, temporary_path
local status, err = pcall(function()
if not self.branch and not self.commit then
+ temporary_path = TMPDIR .. PATHSEP .. "transient-repo"
path = self.repo_path .. PATHSEP .. "master"
- common.mkdirp(path)
+ common.rmrf(temporary_path)
+ common.mkdirp(temporary_path)
log_progress_action("Fetching " .. self.remote .. ":master/main...")
- system.init(path, self.remote)
- system.fetch(path, write_progress_bar)
- if not pcall(system.reset, path, "refs/remotes/origin/master", "hard") then
- if pcall(system.reset, path, "refs/remotes/origin/main", "hard") then
- common.rename(path, self.repo_path .. PATHSEP .. "main")
+ system.init(temporary_path, self.remote)
+ system.fetch(temporary_path, write_progress_bar)
+ if not pcall(system.reset, temporary_path, "refs/remotes/origin/master", "hard") then
+ if pcall(system.reset, temporary_path, "refs/remotes/origin/main", "hard") then
path = self.repo_path .. PATHSEP .. "main"
self.branch = "main"
else
@@ -1131,16 +1132,22 @@ function Repository:fetch()
path = self.local_path
local exists = system.stat(path)
if not exists then
- common.mkdirp(path)
- system.init(path, self.remote)
+ temporary_path = TMPDIR .. PATHSEP .. "tranient-repo"
+ common.rmrf(temporary_path)
+ common.mkdirp(temporary_path)
+ system.init(temporary_path, self.remote)
end
if not exists or self.branch then
log_progress_action("Fetching " .. self.remote .. ":" .. (self.commit or self.branch) .. "...")
- system.fetch(path, write_progress_bar)
- common.reset(path, self.commit or self.branch, "hard")
+ system.fetch(temporary_path or path, write_progress_bar)
+ common.reset(temporary_path or path, self.commit or self.branch, "hard")
end
self.manifest = nil
end
+ if temporary_path then
+ common.mkdirp(path)
+ common.rename(temporary_path, path)
+ end
end)
if not status then
if path then
@@ -1173,7 +1180,7 @@ function Repository:update(pull_remotes)
if self.branch then
system.fetch(self.local_path)
common.reset(self.local_path, self.branch, "hard")
- log_action("Updated " .. self:url())
+ log_action("Updated " .. self:url() .. ".", "green")
self.manifest = nil
manifest, remotes = self:parse_manifest()
end
@@ -1453,11 +1460,9 @@ end
local DEFAULT_REPOS
local function lpm_repo_init(repos)
DEFAULT_REPOS = { Repository.url("https://github.com/adamharrison/lite-xl-plugin-manager.git:latest") }
- if not system.stat(CACHEDIR .. PATHSEP .. "repos") then
+ if not system.stat(CACHEDIR .. PATHSEP .. "settings.json") then
for i, repository in ipairs(repos or DEFAULT_REPOS) do
- if not system.stat(repository.local_path) then
- table.insert(repositories, repository:add(true))
- end
+ table.insert(repositories, repository:add(true))
end
lpm_repo_save()
end
@@ -1788,7 +1793,7 @@ local function lpm_bottle_purge()
end
local function lpm_purge()
- log_action("Removed " .. CACHEDIR .. ".")
+ log_action("Purged " .. CACHEDIR .. ".", "green")
common.rmrf(CACHEDIR)
end