Skip to content

Commit a04a4c0

Browse files
committed
Fix lain.fs for updated btrfs. Add profiler.
1 parent 07ced42 commit a04a4c0

File tree

3 files changed

+314
-52
lines changed

3 files changed

+314
-52
lines changed

lain/widget/fs.lua

Lines changed: 92 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,70 @@
77
88
--]]
99

10-
local helpers = require("lain.helpers")
11-
local Gio = require("lgi").Gio
12-
local focused = require("awful.screen").focused
13-
local wibox = require("wibox")
14-
local naughty = require("naughty")
15-
local gears = require("gears")
16-
local math = math
17-
local string = string
18-
local tconcat = table.concat
19-
local type = type
20-
local query_size = Gio.FILE_ATTRIBUTE_FILESYSTEM_SIZE
21-
local query_free = Gio.FILE_ATTRIBUTE_FILESYSTEM_FREE
22-
local query_used = Gio.FILE_ATTRIBUTE_FILESYSTEM_USED
23-
local query = query_size .. "," .. query_free .. "," .. query_used
10+
local helpers = require("lain.helpers")
11+
local Gio = require("lgi").Gio
12+
local focused = require("awful.screen").focused
13+
local wibox = require("wibox")
14+
local naughty = require("naughty")
15+
local gears = require("gears")
16+
local math = math
17+
local string = string
18+
local tconcat = table.concat
19+
local type = type
20+
local query_size = Gio.FILE_ATTRIBUTE_FILESYSTEM_SIZE
21+
local query_free = Gio.FILE_ATTRIBUTE_FILESYSTEM_FREE
22+
local query_used = Gio.FILE_ATTRIBUTE_FILESYSTEM_USED
23+
local query = query_size .. "," .. query_free .. "," .. query_used
24+
local unix_mount_get_fs_type = Gio.unix_mount_get_fs_type
25+
local unix_mount_get_mount_path = Gio.unix_mount_get_mount_path
2426

2527
-- File systems info
2628
-- lain.widget.fs
2729

2830
local function factory(args)
29-
args = args or {}
31+
args = args or {}
32+
local only = args.only
33+
local skip_types = args.skip_types or {
34+
autofs = true,
35+
nfs = true,
36+
nfs4 = true,
37+
cifs = true,
38+
smbfs = true,
39+
sshfs = true,
40+
["fuse.gvfsd-fuse"] = true,
41+
fuse = true,
42+
gvfs = true,
43+
davfs = true,
44+
afpfs = true
45+
}
46+
local function should_skip(path, fstype)
47+
if only then
48+
local allow = false
49+
for _, p in ipairs(only) do
50+
if p == path then
51+
allow = true; break
52+
end
53+
end
54+
if not allow then return true end
55+
end
56+
if not fstype then return false end
57+
if skip_types[fstype] then return true end
58+
if path:match("^/proc") or path:match("^/sys") or path:match("^/dev") or path:match("^/run") then return true end
59+
if path:match("^/run/user/.+/gvfs") or path:match("^/net") then return true end
60+
return false
61+
end
3062

3163
local fs = {
3264
widget = args.widget or wibox.widget.textbox(),
3365
units = {
34-
[1] = "Kb", [2] = "Mb", [3] = "Gb",
35-
[4] = "Tb", [5] = "Pb", [6] = "Eb",
36-
[7] = "Zb", [8] = "Yb"
66+
[1] = "Kb",
67+
[2] = "Mb",
68+
[3] = "Gb",
69+
[4] = "Tb",
70+
[5] = "Pb",
71+
[6] = "Eb",
72+
[7] = "Zb",
73+
[8] = "Yb"
3774
}
3875
}
3976

@@ -54,11 +91,11 @@ local function factory(args)
5491
end)
5592
end
5693

57-
local timeout = args.timeout or 600
58-
local partition = args.partition
59-
local threshold = args.threshold or 99
60-
local showpopup = args.showpopup or "on"
61-
local settings = args.settings or function() end
94+
local timeout = args.timeout or 600
95+
local partition = args.partition
96+
local threshold = args.threshold or 99
97+
local showpopup = args.showpopup or "on"
98+
local settings = args.settings or function() end
6299

63100
fs.followtag = args.followtag or false
64101
fs.notification_preset = args.notification_preset
@@ -77,31 +114,34 @@ local function factory(args)
77114

78115
local notifypaths = {}
79116
for _, mount in ipairs(Gio.unix_mounts_get()) do
80-
local path = Gio.unix_mount_get_mount_path(mount)
81-
local root = Gio.File.new_for_path(path)
82-
local info = root:query_filesystem_info(query)
83-
84-
if info then
85-
local size = info:get_attribute_uint64(query_size)
86-
local used = info:get_attribute_uint64(query_used)
87-
local free = info:get_attribute_uint64(query_free)
88-
89-
if size > 0 then
90-
local units = math.floor(math.log(size)/math.log(1024))
91-
92-
fs_now[path] = {
93-
units = fs.units[units],
94-
percentage = math.floor(100 * used / size), -- used percentage
95-
size = size / math.pow(1024, units),
96-
used = used / math.pow(1024, units),
97-
free = free / math.pow(1024, units)
98-
}
99-
100-
if fs_now[path].percentage > 0 then -- don't notify unused file systems
101-
notifypaths[#notifypaths+1] = path
102-
103-
if #path > pathlen then
104-
pathlen = #path
117+
local path = unix_mount_get_mount_path(mount)
118+
local fstype = unix_mount_get_fs_type(mount)
119+
if not should_skip(path, fstype) then
120+
local root = Gio.File.new_for_path(path)
121+
local info = root:query_filesystem_info(query)
122+
123+
if info then
124+
local size = info:get_attribute_uint64(query_size)
125+
local used = info:get_attribute_uint64(query_used)
126+
local free = info:get_attribute_uint64(query_free)
127+
128+
if size > 0 then
129+
local units = math.floor(math.log(size) / math.log(1024))
130+
131+
fs_now[path] = {
132+
units = fs.units[units],
133+
percentage = math.floor(100 * used / size),
134+
size = size / math.pow(1024, units),
135+
used = used / math.pow(1024, units),
136+
free = free / math.pow(1024, units)
137+
}
138+
139+
if fs_now[path].percentage > 0 then
140+
notifypaths[#notifypaths + 1] = path
141+
142+
if #path > pathlen then
143+
pathlen = #path
144+
end
105145
end
106146
end
107147
end
@@ -128,7 +168,8 @@ local function factory(args)
128168
local notifytable = { [1] = string.format(fmt, "path", "used", "free", "size") }
129169
fmt = "\n%-" .. tostring(pathlen) .. "s %3s%%\t%6.2f\t%6.2f %s"
130170
for _, path in ipairs(notifypaths) do
131-
notifytable[#notifytable+1] = string.format(fmt, path, fs_now[path].percentage, fs_now[path].free, fs_now[path].size, fs_now[path].units)
171+
notifytable[#notifytable + 1] = string.format(fmt, path, fs_now[path].percentage, fs_now[path].free,
172+
fs_now[path].size, fs_now[path].units)
132173
end
133174

134175
fs.notification_preset.text = tconcat(notifytable)
@@ -144,8 +185,8 @@ local function factory(args)
144185
end
145186

146187
if showpopup == "on" then
147-
fs.widget:connect_signal('mouse::enter', function () fs.show(0) end)
148-
fs.widget:connect_signal('mouse::leave', function () fs.hide() end)
188+
fs.widget:connect_signal('mouse::enter', function() fs.show(0) end)
189+
fs.widget:connect_signal('mouse::leave', function() fs.hide() end)
149190
end
150191

151192
helpers.newtimer(partition or "fs", timeout, fs.update)

0 commit comments

Comments
 (0)