From be9ae6862fd89b31e1177a1b302609cf04358ed0 Mon Sep 17 00:00:00 2001 From: Luca CPZ Date: Sun, 25 Feb 2018 23:17:09 +0100 Subject: [PATCH 1/1] widget.fs: assure that each processed partition has non nil infos; awesome-copycats #225 --- widget/fs.lua | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/widget/fs.lua b/widget/fs.lua index 5e18491..e680a3c 100644 --- a/widget/fs.lua +++ b/widget/fs.lua @@ -74,26 +74,28 @@ local function factory(args) local path = Gio.unix_mount_get_mount_path(mount) local root = Gio.File.new_for_path(path) local info = root:query_filesystem_info(query) - local size = info:get_attribute_uint64(query_size) - local used = info:get_attribute_uint64(query_used) - local free = info:get_attribute_uint64(query_free) - - if size > 0 then - local units = math.floor(math.log(size)/math.log(1024)) - - fs_now[path] = { - units = fs.units[units], - percentage = math.floor(100 * used / size), -- used percentage - size = size / math.pow(1024, math.floor(units)), - used = used / math.pow(1024, math.floor(units)), - free = free / math.pow(1024, math.floor(units)) - } - -- don't notify unused file systems - if fs_now[path].percentage > 0 then - notifytable[#notifytable+1] = sformat("\n%-10s %-5s %3.2f\t%3.2f\t%s", path, - fs_now[path].percentage .. "%", fs_now[path].free, fs_now[path].size, - fs_now[path].units) + if info then + local size = info:get_attribute_uint64(query_size) + local used = info:get_attribute_uint64(query_used) + local free = info:get_attribute_uint64(query_free) + + if size > 0 then + local units = math.floor(math.log(size)/math.log(1024)) + + fs_now[path] = { + units = fs.units[units], + percentage = math.floor(100 * used / size), -- used percentage + size = size / math.pow(1024, math.floor(units)), + used = used / math.pow(1024, math.floor(units)), + free = free / math.pow(1024, math.floor(units)) + } + + if fs_now[path].percentage > 0 then -- don't notify unused file systems + notifytable[#notifytable+1] = sformat("\n%-10s %-5s %3.2f\t%3.2f\t%s", path, + fs_now[path].percentage .. "%", fs_now[path].free, fs_now[path].size, + fs_now[path].units) + end end end end -- 2.39.5