From 21737136944af4e38a601f3767124ae5626f25b6 Mon Sep 17 00:00:00 2001 From: WahPlus Date: Sat, 28 Mar 2026 06:50:26 +0200 Subject: [PATCH] Added package deduplication and fixed a previously unnoticed bug with extending the package table mid-loop See comments for more details --- halyde/apps/ag2.lua | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/halyde/apps/ag2.lua b/halyde/apps/ag2.lua index e517da8..606ba18 100644 --- a/halyde/apps/ag2.lua +++ b/halyde/apps/ag2.lua @@ -146,8 +146,23 @@ end -- Check if everything is valid failure = false local dependencyCounter = 0 +local previousI = 1 -- See 190 +::RESETLOOP:: if command == "install" then - for i = 1, #packages do + for i = previousI, #packages do + if not packages[i] then + -- When packages are removed, the last packages can end up reading as nil + goto SKIP + end + local otherPackages = table.copy(packages) + table.remove(otherPackages, i) + -- This is to check if the package can be found in the others, or in other words, checking for duplicates + if table.find(otherPackages, packages[i]) then + print(("\27[93mDuplicate package specified (%s), skipping"):format(packages[i])) + table.remove(packages, i) + i = i - 1 + goto SKIP + end local source if parsed.s or parsed.source then source = parsed.s or parsed.source @@ -170,6 +185,10 @@ if command == "install" then for _, package in ipairs(packageConfig.packages) do table.insert(packages, package) end + previousI = i + goto RESETLOOP + -- Apparently "for i = 1, n" loops don't change when n changes. So when the table gets extended, packages near the end won't get picked up. + -- This is why it is needed to restart the loop. elseif packageConfig.type == "virtual-package" then print(("Installing virtual package %s"):format(packages[i])) local pkgAskText = ("Select a package by typing in its number: 1) %s"):format(packageConfig.packages[1])