fix /bin/install to not suggest source of only rw option

This commit is contained in:
payonel 2017-07-04 15:35:21 -07:00
parent ed05bd11b7
commit 4b286e2479
2 changed files with 34 additions and 6 deletions

View File

@ -89,12 +89,10 @@ for dev, path in pairs(devices) do
end end
local target = targets[1] local target = targets[1]
if #targets ~= 1 then -- if there is only 1 target, the source selection cannot include it
utils = loadfile(utils_path, "bt", _G) if #targets == 1 then
target = utils("select", "targets", options, targets) devices[targets[1].dev] = nil
end end
if not target then return end
devices[target.dev] = nil
for dev, path in pairs(devices) do for dev, path in pairs(devices) do
local address = dev.address local address = dev.address
@ -127,13 +125,29 @@ for dev, path in pairs(devices) do
end end
end end
-- Ask the user to select a source
local source = sources[1] local source = sources[1]
if #sources ~= 1 then if #sources ~= 1 then
utils = utils or loadfile(utils_path, "bt", _G) utils = loadfile(utils_path, "bt", _G)
source = utils("select", "sources", options, sources) source = utils("select", "sources", options, sources)
end end
if not source then return end if not source then return end
-- Remove the source from the target options
for index,entry in ipairs(targets) do
if entry.dev == source.dev then
table.remove(targets, index)
target = targets[1]
end
end
-- Ask the user to select a target
if #targets ~= 1 then
utils = utils or loadfile(utils_path, "bt", _G)
target = utils("select", "targets", options, targets)
end
if not target then return end
options = options =
{ {
from = source.path .. '/', from = source.path .. '/',

View File

@ -53,6 +53,20 @@ if cmd == "select" then
end end
os.exit(1) os.exit(1)
end end
local index_of_rw_source
for index,entry in ipairs(devices) do
if not entry.dev.isReadOnly() then
if index_of_rw_source then
-- this means there was another rw source, no special action required
index_of_rw_source = nil
break
end
index_of_rw_source = index
end
end
if index_of_rw_source then
table.remove(devices, index_of_rw_source)
end
return select_prompt(devices, "What do you want to install?") return select_prompt(devices, "What do you want to install?")
elseif arg == "targets" then elseif arg == "targets" then
if #devices == 0 then if #devices == 0 then