Skip to content

Commit 643783c

Browse files
author
Alice Jenkinson
committed
Merge pull request NuckChorris#15 from LoathingKernel/open_files
awesomewm: Close files after read.
2 parents 2ac2cba + 7db401f commit 643783c

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

awesomewm/assault.lua

+14-4
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,25 @@ end
2828
local acpi_is_on_ac_power = function (adapter)
2929
local f = io.open('/sys/class/power_supply/' .. adapter .. '/online')
3030
if f == nil then return false end
31-
return string.find(f:read(), '1')
31+
local o = f:read()
32+
f:close()
33+
return string.find(o, '1')
3234
end
3335

3436
local acpi_battery_is_present = function (battery)
3537
local f = io.open('/sys/class/power_supply/' .. battery .. '/present')
3638
if f == nil then return false end
37-
return string.find(f:read(), '1')
39+
local o = f:read()
40+
f:close()
41+
return string.find(o, '1')
3842
end
3943

4044
local acpi_battery_is_charging = function (battery)
4145
local f = io.open('/sys/class/power_supply/' .. battery .. '/status')
4246
if f == nil then return false end
43-
return string.find(f:read(), 'Charging')
47+
local o = f:read()
48+
f:close()
49+
return string.find(o, 'Charging')
4450
end
4551

4652
local acpi_battery_percent = function (battery)
@@ -49,7 +55,11 @@ local acpi_battery_percent = function (battery)
4955
local full = io.open('/sys/class/power_supply/' .. battery .. '/energy_full') or
5056
io.open('/sys/class/power_supply/' .. battery .. '/charge_full')
5157
if (now == nil) or (full == nil) then return 0 end
52-
return tonumber(now:read())/tonumber(full:read())
58+
local out_n = now:read()
59+
now:close()
60+
local out_f = full:read()
61+
full:close()
62+
return tonumber(out_n)/tonumber(out_f)
5363
end
5464

5565
local battery_bolt_generate = function (width, height)

0 commit comments

Comments
 (0)