From 8ed253716c60f3279518ce34c74ca053530039d8 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Fri, 24 Jan 2025 21:35:21 +0800 Subject: [PATCH] fix: `lsblk` output potentially out of order --- mount.yazi/main.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mount.yazi/main.lua b/mount.yazi/main.lua index 23a2c0f..82a4da1 100644 --- a/mount.yazi/main.lua +++ b/mount.yazi/main.lua @@ -207,22 +207,22 @@ function M.fillin(tbl) local sources, indices = {}, {} for i, p in ipairs(tbl) do 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 if #sources == 0 then return tbl 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 ya.dbg("Failed to fetch filesystem types for unmounted partitions: " .. err) return tbl end - local i = 1 - for line in output.stdout:gmatch("[^\r\n]+") do - i, tbl[indices[i]].fstype = i + 1, line + local t = ya.json_decode(output and output.stdout or "") + for _, p in ipairs(t and t.blockdevices or {}) do + tbl[indices[p.name]].fstype = p.fstype end return tbl end