Changeset 2162


Ignore:
Timestamp:
Aug 23, 2012, 3:32:21 PM (7 years ago)
Author:
matthijs
Message:

mountd/plugin-torrent: Restructure disk listing

Instead of looking at /tmp/mounts, it looks through the uci state to
find valid mounts with a fmg image installed or for installing the fmg
mount.

Doing this allows us to get at extra info about the mount, such as the
filesystem used.

To prevent the luci code from becoming more complicated by this, the
separate "install" page in plugin-torrent is removed. Instead of doing
the startup (and install if there is only one free partition) on one
page and the install from another page (if there are multiple free
partitions), there is now a single page that shows all partitions and
allows starting up from installed partitions and installing to free
partitions

References: #1186

Location:
trunk
Files:
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/fon/mountd/files/usr/lib/lua/luci/fmg.lua

    r1274 r2162  
    4848end
    4949
    50 function find_discs(img, disc)
    51         -- protect against execute injection
    52         local uci = require("luci.model.uci").cursor()
    53         local sane = uci:get("fmg", img, "name")
    54         if not(sane) then
    55                 return
    56         end
    57         local fw = uci:get("system", "fon", "firmware").."."..uci:get("system", "fon", "revision")
    58         local d = luci.util.exec("find /tmp/mounts/*/FoneraApps/"..img.."."..fw..".fmg | cut -d/ -f4")
    59         local a = {}
    60         local p
    61         while(string.find(d, string.char(10))) do
    62                 local p = string.find(d, string.char(10))
    63                 a[#a+1] = string.sub(d, 1, p - 1)
    64                 d = string.sub(d, p + 1)
    65                 if a[#a] == disc then
    66                         return true
    67                 end
    68         end
    69         if disc then
    70                 return false
    71         end
    72         return a
    73 end
    74 
    75 function find_discs_free(img)
     50function find_discs(img)
    7651        -- protect against execute injection
    7752        local sane = require("luci.model.uci").cursor():get("fmg", img, "name")
     
    7954                return
    8055        end
    81         local f = luci.util.exec("ls /tmp/mounts/ |tr \" \" \""..string.char(10).."\"")
     56        local uci = require("luci.model.uci").cursor()
     57        local fw = uci:get("system", "fon", "firmware").."."..uci:get("system", "fon", "revision")
     58        local posix = require("posix")
     59
     60        local uci_state = require("luci.model.uci").cursor_state()
    8261        local a = {}
    83         local p
    84         while(f:find(string.char(10))) do
    85                 local p = f:find(string.char(10))
    86                 local n = f:sub(1, p - 1)
    87                 if not(find_discs(img, n)) then
    88                         a[#a+1] = n
     62        uci_state:foreach("mountd", "mountd_disc", function(s)
     63                for i = 1, 8, 1 do
     64                        name = s["part"..i.."name"]
     65                        supported = s["part"..i.."supported"]
     66                        err = s["part"..i.."error"]
     67
     68                        if name and supported == "1" and err == "0" then
     69                                img_path = "/tmp/mounts/"..name.."/FoneraApps/"..img.."."..fw..".fmg"
     70                                installed = posix.stat(img_path) ~= nil
     71                                a[#a+1] = {name=name, installed=installed}
     72                        end
    8973                end
    90                 f = f:sub(p + 1)
    91         end
     74        end)
     75
    9276        return a
    9377end
  • trunk/luci/applications/luci-torrent/luasrc/controller/torrent.lua

    r1316 r2162  
    5959        if fmg ~= "1" then
    6060                local e = entry({"torrent"}, template("torrent/notrunning"), luci.i18n.translate("torrent_title", "Torrent Transmission"))
    61                 setup_base(e)
    62                 local e = entry({"torrent", "install"}, template("torrent/install"), luci.i18n.translate("torrent_title", "Torrent Transmission"))
    6361                setup_base(e)
    6462                return
  • trunk/luci/applications/luci-torrent/luasrc/view/torrent/notrunning.htm

    r1257 r2162  
    1010<%
    1111local discs = require("luci.fmg").find_discs("torrent")
    12 local inst_disc = require("luci.model.uci").cursor_state():get("fmg", "torrent", "instdisc")
    13 local free_discs = require("luci.fmg").find_discs_free("torrent")
    14 for i,v in ipairs(discs) do
    15                 if inst_disc ~= v then%>
     12local free = nil
     13for i,v in ipairs(discs) do
     14        if v.installed then
     15%>
    1616        <li>
    17                 <a id="startup" class="icon" href="<%=luci.dispatcher.build_url("torrent", "startup")%>?disc=<%=v%>" style="background-image: url(<%=luci.config.main.resourcebase%>/icons/plugins/torrent.png);"><%:torrent_startup Startup%> <%=v%></a>
     17                <a id="startup" class="icon" href="<%=luci.dispatcher.build_url("torrent", "startup")%>?disc=<%=v.name%>" style="background-image: url(<%=luci.config.main.resourcebase%>/icons/plugins/torrent.png);"><%:torrent_startup Startup%> <%=v.name%></a>
    1818        </li>
    19                 <%end
    20         end
    21         if #free_discs == 1 then%>
     19<%      end
     20end
     21for i,v in ipairs(discs) do
     22        if not v.installed then %>
    2223        <li>
    23                 <a id="startup" class="icon" href="<%=luci.dispatcher.build_url("torrent", "download")%>?disc=<%=free_discs[1]%>" style="background-image: url(<%=luci.config.main.mediaurlbase%>/icons/firmware.png);"><%:torrent_install Install on%> <%=free_discs[1]%></a>
     24        <a id="startup" class="icon" href="<%=luci.dispatcher.build_url("torrent", "download")%>?disc=<%=v.name%>" style="background-image: url(<%=luci.config.main.mediaurlbase%>/icons/firmware.png);"><%:torrent_install Install on%> <%=v.name%></a>
    2425        </li>
    25         <%elseif #free_discs > 1 then%>
    26         <li>
    27                 <a id="install" class="icon" href="<%=luci.dispatcher.build_url("torrent", "install")%>" style="background-image: url(<%=luci.config.main.mediaurlbase%>/icons/firmware.png);"><%:torrent_install Install%> <%=v%></a>
    28         </li>
    29         <%end%>
     26        <%end
     27end %>
    3028</ul>
    3129        <%end%>
Note: See TracChangeset for help on using the changeset viewer.