From fcc5d1e3c77c5d453c887e8b7c99aec00b9f079b Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Sun, 28 Feb 2010 23:43:17 +0000 Subject: [PATCH] luci-0.9: rewrite package management to be less OOM prone --- .../luasrc/controller/admin/system.lua | 81 +++++-------- .../luasrc/view/admin_system/packages.htm | 108 +++++++++++------- 2 files changed, 96 insertions(+), 93 deletions(-) diff --git a/modules/admin-full/luasrc/controller/admin/system.lua b/modules/admin-full/luasrc/controller/admin/system.lua index a273ff3f30..f86fa04042 100644 --- a/modules/admin-full/luasrc/controller/admin/system.lua +++ b/modules/admin-full/luasrc/controller/admin/system.lua @@ -38,90 +38,63 @@ end function action_packages() local ipkg = require("luci.model.ipkg") - local void = nil local submit = luci.http.formvalue("submit") local changes = false - - + local install = { } + local remove = { } + -- Search query local query = luci.http.formvalue("query") query = (query ~= '') and query or nil -- Packets to be installed - local install = submit and luci.http.formvaluetable("install") - + local ninst = submit and luci.http.formvalue("install") + local uinst = nil + -- Install from URL local url = luci.http.formvalue("url") if url and url ~= '' and submit then - if not install then - install = {} - end - install[url] = 1 - changes = true + uinst = url end - + -- Do install - if install then - for k, v in pairs(install) do - void, install[k] = ipkg.install(k) - end + if ninst then + _, install[ninst] = ipkg.install(ninst) changes = true end - - + + if uinst then + _, install[uinst] = ipkg.install(uinst) + changes = true + end + -- Remove packets - local remove = submit and luci.http.formvaluetable("remove") - if remove then - for k, v in pairs(remove) do - void, remove[k] = ipkg.remove(k) - end + local rem = submit and luci.http.formvalue("remove") + if rem then + _, remove[rem] = ipkg.remove(rem) changes = true end - + -- Update all packets local update = luci.http.formvalue("update") if update then - void, update = ipkg.update() + _, update = ipkg.update() end -- Upgrade all packets local upgrade = luci.http.formvalue("upgrade") if upgrade then - void, upgrade = ipkg.upgrade() + _, upgrade = ipkg.upgrade() end + - - -- Package info - local info = luci.model.ipkg.info(query and "*"..query.."*") - info = info or {} - local pkgs = {} - - -- Sort after status and name - for k, v in pairs(info) do - local x = 0 - for i, j in pairs(pkgs) do - local vins = (v.Status and v.Status.installed) - local jins = (j.Status and j.Status.installed) - if vins ~= jins then - if vins then - break - end - else - if j.Package > v.Package then - break - end - end - x = i - end - table.insert(pkgs, x+1, v) - end - - luci.template.render("admin_system/packages", {pkgs=pkgs, query=query, - install=install, remove=remove, update=update, upgrade=upgrade}) - + luci.template.render("admin_system/packages", { + query=query, install=install, remove=remove, update=update, upgrade=upgrade + }) + -- Remove index cache if changes then nixio.fs.unlink("/tmp/luci-indexcache") diff --git a/modules/admin-full/luasrc/view/admin_system/packages.htm b/modules/admin-full/luasrc/view/admin_system/packages.htm index 5cd9f635a6..8cba08a109 100644 --- a/modules/admin-full/luasrc/view/admin_system/packages.htm +++ b/modules/admin-full/luasrc/view/admin_system/packages.htm @@ -30,28 +30,7 @@ function opkg_error(code) end -%> <%+header%> -

<%:system%>

-

<%:a_s_packages%>

- -
- -<% if install or remove or update or upgrade then %> -
<%:status%>:
-<% if update then %> - <%:a_s_packages_update%>: <% if update == 0 then %><%:ok%><% else %><%:error%> (<%=opkg_error(update)%>)<% end %>
-<% end %> -<% if upgrade then%> - <%:a_s_packages_upgrade%>: <% if upgrade == 0 then %><%:ok%><% else %><%:error%> (<%=opkg_error(upgrade)%>)<% end %>
-<% end %> -<% if install then for k,v in pairs(install) do %> - <%:a_s_packages_install%> '<%=k%>': <% if v == 0 then %><%:ok%><% else %><%:error%> (<%=opkg_error(v)%>)<% end %>
-<% end end %> -<% if remove then for k,v in pairs(remove) do %> - <%:a_s_packages_remove%> '<%=k%>': <% if v == 0 then %><%:ok%><% else %><%:error%> (<%=opkg_error(v)%>)<% end %>
-<% end end %> -
-
-<% end %> +

<%:system%> - <%:a_s_packages%>

@@ -77,32 +56,83 @@ end
+ + + + <% if (install and next(install)) or (remove and next(remove)) or update or upgrade then %> +

<%:status%>

+
+ <% if update then %> + <%:a_s_packages_update%>: <% if update == 0 then %><%:ok%><% else %><%:error%> (<%=opkg_error(update)%>)<% end %>
+ <% end %> + <% if upgrade then%> + <%:a_s_packages_upgrade%>: <% if upgrade == 0 then %><%:ok%><% else %><%:error%> (<%=opkg_error(upgrade)%>)<% end %>
+ <% end %> + <% if install then for k,v in pairs(install) do %> + <%:a_s_packages_install%> '<%=k%>': <% if v == 0 then %><%:ok%><% else %><%:error%> (<%=opkg_error(v)%>)<% end %>
+ <% end end %> + <% if remove then for k,v in pairs(remove) do %> + <%:a_s_packages_remove%> '<%=k%>': <% if v == 0 then %><%:ok%><% else %><%:error%> (<%=opkg_error(v)%>)<% end %>
+ <% end end %> +
+
+ <% end %> + +

<%:a_s_packages_installed Installed packages%><% if query then %> (<%=luci.util.pcdata(query)%>)<% end %>

- +
+
- - - - - + + + - <% for k, pkg in pairs(pkgs) do %> + <% local empty = true; luci.model.ipkg.list_installed(query, function(n, v, d) empty = false %> - - - - - + + + + + <% end) %> + <% if empty then %> + + + + <% end %>
<%:a_s_packages_name%><%:version%><%:install%><%:delete%><%:descr%> <%:a_s_packages_name%><%:version%>
<%=luci.util.pcdata(pkg.Package)%><%=luci.util.pcdata(pkg.Version)%><% if not pkg.Status or not pkg.Status.installed then %><% else %><%:installed%><% end %><% if pkg.Status and pkg.Status.installed then %><% else %><%:notinstalled%><% end %><%=luci.util.pcdata(pkg.Description)%><%:delete%><%=luci.util.pcdata(n)%><%=luci.util.pcdata(v)%>
 <%:none%><%:none%>
+ -
-
- -
- +

<%:a_s_packages_available Available packages%><% if query then %> (<%=luci.util.pcdata(query)%>)<% end %>

+ +
+ + + + + + + + <% local empty = true; luci.model.ipkg.list_all(query, function(n, v, d) empty = false %> + + + + + + + <% end) %> + <% if empty then %> + + + + + + + <% end %> +
 <%:a_s_packages_name%><%:version%><%:descr%>
<%:install%><%=luci.util.pcdata(n)%><%=luci.util.pcdata(v)%><%=luci.util.pcdata(d)%>
 <%:none%><%:none%><%:none%>
+
<%+footer%> -- 2.30.2