feat: support disk devices with no sub-partitions (#69)
This commit is contained in:
committed by
GitHub
parent
8945e543eb
commit
beb586aed0
2
.github/DISCUSSION_TEMPLATE/1-q-a.yml
vendored
2
.github/DISCUSSION_TEMPLATE/1-q-a.yml
vendored
@@ -50,5 +50,7 @@ body:
|
|||||||
label: Checklist
|
label: Checklist
|
||||||
description: Before submitting the post, please make sure you have completed the following
|
description: Before submitting the post, please make sure you have completed the following
|
||||||
options:
|
options:
|
||||||
|
- label: I have read all the documentation
|
||||||
|
required: true
|
||||||
- label: I have searched the existing discussions/issues
|
- label: I have searched the existing discussions/issues
|
||||||
required: true
|
required: true
|
||||||
|
|||||||
@@ -144,10 +144,12 @@ function M:reflow() return { self } end
|
|||||||
function M:redraw()
|
function M:redraw()
|
||||||
local rows = {}
|
local rows = {}
|
||||||
for _, p in ipairs(self.partitions or {}) do
|
for _, p in ipairs(self.partitions or {}) do
|
||||||
if p.sub == "" then
|
if not p.sub then
|
||||||
rows[#rows + 1] = ui.Row { p.main }
|
rows[#rows + 1] = ui.Row { p.main }
|
||||||
|
elseif p.sub == "" then
|
||||||
|
rows[#rows + 1] = ui.Row { p.main, p.label or "", p.dist or "", p.fstype or "" }
|
||||||
else
|
else
|
||||||
rows[#rows + 1] = ui.Row { p.sub, p.label or "", p.dist or "", p.fstype or "" }
|
rows[#rows + 1] = ui.Row { " " .. p.sub, p.label or "", p.dist or "", p.fstype or "" }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -176,26 +178,24 @@ function M.obtain()
|
|||||||
local tbl = {}
|
local tbl = {}
|
||||||
local last
|
local last
|
||||||
for _, p in ipairs(fs.partitions()) do
|
for _, p in ipairs(fs.partitions()) do
|
||||||
local main, sub
|
local main, sub = M.split(p.src)
|
||||||
if ya.target_os() == "macos" then
|
if main and last ~= main then
|
||||||
main, sub = p.src:match("^(/dev/disk%d+)(.+)$")
|
if p.src == main then
|
||||||
elseif p.src:find("/dev/nvme", 1, true) == 1 then -- /dev/nvme0n1p1
|
last, p.main, p.sub, tbl[#tbl + 1] = p.src, p.src, "", p
|
||||||
main, sub = p.src:match("^(/dev/nvme%d+n%d+)(p%d+)$")
|
else
|
||||||
elseif p.src:find("/dev/mmcblk", 1, true) == 1 then -- /dev/mmcblk0p1
|
|
||||||
main, sub = p.src:match("^(/dev/mmcblk%d+)(p%d+)$")
|
|
||||||
elseif p.src:find("/dev/sd", 1, true) == 1 then -- /dev/sda1
|
|
||||||
main, sub = p.src:match("^(/dev/sd[a-z])(%d+)$")
|
|
||||||
end
|
|
||||||
if sub then
|
|
||||||
if last ~= main then
|
|
||||||
last, tbl[#tbl + 1] = main, { src = main, main = main, sub = "" }
|
last, tbl[#tbl + 1] = main, { src = main, main = main, sub = "" }
|
||||||
end
|
end
|
||||||
p.main, p.sub, tbl[#tbl + 1] = main, " " .. sub, p
|
end
|
||||||
|
if sub then
|
||||||
|
if tbl[#tbl].sub == "" and tbl[#tbl].main == main then
|
||||||
|
tbl[#tbl].sub = nil
|
||||||
|
end
|
||||||
|
p.main, p.sub, tbl[#tbl + 1] = main, sub, p
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
table.sort(M.fillin(tbl), function(a, b)
|
table.sort(M.fillin(tbl), function(a, b)
|
||||||
if a.main == b.main then
|
if a.main == b.main then
|
||||||
return a.sub < b.sub
|
return (a.sub or "") < (b.sub or "")
|
||||||
else
|
else
|
||||||
return a.main > b.main
|
return a.main > b.main
|
||||||
end
|
end
|
||||||
@@ -203,6 +203,21 @@ function M.obtain()
|
|||||||
return tbl
|
return tbl
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.split(src)
|
||||||
|
local pats = {
|
||||||
|
{ "^/dev/sd[a-z]", "%d+$" }, -- /dev/sda1
|
||||||
|
{ "^/dev/nvme%d+n%d+", "p%d+$" }, -- /dev/nvme0n1p1
|
||||||
|
{ "^/dev/mmcblk%d+", "p%d+$" }, -- /dev/mmcblk0p1
|
||||||
|
{ "^/dev/disk%d+", ".+$" }, -- /dev/disk1s1
|
||||||
|
}
|
||||||
|
for _, p in ipairs(pats) do
|
||||||
|
local main = src:match(p[1])
|
||||||
|
if main then
|
||||||
|
return main, src:sub(#main + 1):match(p[2])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function M.fillin(tbl)
|
function M.fillin(tbl)
|
||||||
if ya.target_os() ~= "linux" then
|
if ya.target_os() ~= "linux" then
|
||||||
return tbl
|
return tbl
|
||||||
@@ -210,7 +225,7 @@ function M.fillin(tbl)
|
|||||||
|
|
||||||
local sources, indices = {}, {}
|
local sources, indices = {}, {}
|
||||||
for i, p in ipairs(tbl) do
|
for i, p in ipairs(tbl) do
|
||||||
if p.sub ~= "" and not p.fstype then
|
if p.sub and not p.fstype then
|
||||||
sources[#sources + 1], indices[p.src] = p.src, i
|
sources[#sources + 1], indices[p.src] = p.src, i
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -235,7 +250,7 @@ function M.operate(type)
|
|||||||
local active = active_partition()
|
local active = active_partition()
|
||||||
if not active then
|
if not active then
|
||||||
return
|
return
|
||||||
elseif active.sub == "" then
|
elseif not active.sub then
|
||||||
return -- TODO: mount/unmount main disk
|
return -- TODO: mount/unmount main disk
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user