fix: lsblk output potentially out of order

This commit is contained in:
sxyazi
2025-01-24 21:35:21 +08:00
parent 117975b88b
commit 8ed253716c

View File

@@ -207,22 +207,22 @@ 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[#indices + 1] = p.src, i sources[#sources + 1], indices[p.src] = p.src, i
end end
end end
if #sources == 0 then if #sources == 0 then
return tbl return tbl
end end
local output, err = Command("lsblk"):args({ "-n", "-o", "FSTYPE" }):args(sources):output() local output, err = Command("lsblk"):args({ "-p", "-o", "name,fstype", "-J" }):args(sources):output()
if err then if err then
ya.dbg("Failed to fetch filesystem types for unmounted partitions: " .. err) ya.dbg("Failed to fetch filesystem types for unmounted partitions: " .. err)
return tbl return tbl
end end
local i = 1 local t = ya.json_decode(output and output.stdout or "")
for line in output.stdout:gmatch("[^\r\n]+") do for _, p in ipairs(t and t.blockdevices or {}) do
i, tbl[indices[i]].fstype = i + 1, line tbl[indices[p.name]].fstype = p.fstype
end end
return tbl return tbl
end end