Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lpm crashes when install plugins to the same DATADIR as USERDIR #134

Open
takase1121 opened this issue Nov 10, 2024 · 2 comments
Open

lpm crashes when install plugins to the same DATADIR as USERDIR #134

takase1121 opened this issue Nov 10, 2024 · 2 comments

Comments

@takase1121
Copy link
Member

This is highlighted in https://github.com/lite-xl/lite-xl/blob/de13b6da2b36e47fbfadf3c491da1f2769e8234d/scripts/build.sh#L222

as the way to "vendor install" a plugin, but actually results in the following error:

src/lpm.lua:1621: attempt to index a nil value (field 'integer index')
stack traceback:
        src/lpm.lua:1621: in method 'all_addons'
        src/lpm.lua:1697: in method 'get_addon'
        src/lpm.lua:1927: in field 'retrieve_addons'
        src/lpm.lua:2007: in field 'install'
        src/lpm.lua:2317: in field 'command'
        src/lpm.lua:2340: in field 'run'
        src/lpm.lua:2859: in function <src/lpm.lua:2858>
        [C]: in field 'flock'
        src/lpm.lua:555: in upvalue 'engage_locks'
        src/lpm.lua:2858: in function <src/lpm.lua:2374>
        [C]: in function 'xpcall'
        src/lpm.lua:2374: in main chunk

The error is caused by this block here:

local addon_paths = {

and here:

if not hash[id] then hash[id] = t[#t] end

When we have a default plugin (let's say language_css), it would be picked up in USERDIR and added to hash. When we loop over DATADIR (which is set to the same directory), the plugin is picked up again, and since it is found in hash, the code assumes that it has valid repository metadata at index 1, which it does not. I am not sure of the exact logic, but this is my best guess.

To fix this, we could:

  1. check if hash[id][1] is really available
  2. remove duplicate paths in addon_paths, since it obviously won't work
  3. add --vendor flag to tell lpm that we are vendor installing stuff

I have a partial implementation of (3) that only works for this particular use case:

diff --git a/src/lpm.lua b/src/lpm.lua
index 111fcc3..040d56a 100644
--- a/src/lpm.lua
+++ b/src/lpm.lua
@@ -1588,10 +1588,10 @@ function Bottle:all_addons()
   if self.all_addons_cache then return self.all_addons_cache end
   local t, hash = get_repository_addons()
   for _, addon_type in ipairs({ "plugins", "libraries", "fonts", "colors" }) do
-    local addon_paths = {
-      (self.local_path and (self.local_path .. PATHSEP .. "user") or USERDIR) .. PATHSEP .. addon_type,
-      self.lite_xl.datadir_path .. PATHSEP .. addon_type
-    }
+    local addon_paths = { (self.local_path and (self.local_path .. PATHSEP .. "user") or USERDIR) .. PATHSEP .. addon_type }
+    if not ARGS["vendor"] then
+      table.insert(addon_paths, self.lite_xl.datadir_path .. PATHSEP .. addon_type)
+    end
     for i, addon_path in ipairs(addon_paths) do
       if system.stat(addon_path) then
         for j, v in ipairs(system.ls(addon_path)) do
@@ -2374,7 +2374,7 @@ end
 xpcall(function()
   rawset(_G, "ARGS", ARGV)
   ARGS = common.args(ARGS, {
-    json = "flag", userdir = "string", cachedir = "string", version = "flag", verbose = "flag",
+    json = "flag", userdir = "string", cachedir = "string", version = "flag", verbose = "flag", vendor = "flag",
     quiet = "flag", version = "flag", ["mod-version"] = "string", remotes = "flag", help = "flag",
     ["ssl-certs"] = "string", force = "flag", arch = "array", ["assume-yes"] = "flag",
     ["no-install-optional"] = "flag", datadir = "string", binary = "string", trace = "flag", progress = "flag",

This patch will be used in https://github.com/lite-xl/playground to bundle plugins.

@adamharrison
Copy link
Member

The issue here is that get_repository_addons is returning t, hash, and it's not actually consistent how hash is being treated. In one place, it's a hash of arrays, in another, it's a hash of objects.

I need to investigate this and shunt it to one or the other.

@adamharrison
Copy link
Member

OK; cde491b should actually fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants