Minor Lua I/O cleanups (#8921)

Mostly making sure we always explicitly close io handles.
reviewable/pr8924/r1
NiLuJe 2 years ago committed by GitHub
parent 26b19acf87
commit 23cd7e24bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -80,11 +80,14 @@ function Dbg:turnOn()
--- @note: On Linux, use CLOEXEC to avoid polluting the fd table of our child processes.
--- Otherwise, it can be problematic w/ wpa_supplicant & USBMS...
--- Note that this is entirely undocumented, but at least LuaJIT passes the mode as-is to fopen, so, we're good.
local open_flags = "w"
if jit.os == "Linux" then
self.ev_log = io.open("ev.log", "we")
else
self.ev_log = io.open("ev.log", "w")
-- Oldest Kindle devices are too old to support O_CLOEXEC...
if os.getenv("KINDLE_LEGACY") ~= "yes" then
open_flags = "we"
end
end
self.ev_log = io.open("ev.log", open_flags)
end
--- Turn off debug mode.
@ -99,7 +102,7 @@ function Dbg:turnOff()
return check
end
if self.ev_log then
io.close(self.ev_log)
self.ev_log:close()
self.ev_log = nil
end
end

@ -140,7 +140,7 @@ function SysfsLight:_write_value(file, value)
return false
end
local ret, err_msg, err_code = f:write(value)
io.close(f)
f:close()
if not ret then
logger.err("Write error: ", err_msg, err_code)
return false

@ -280,6 +280,7 @@ function GetText_mt.__index.changeLang(new_lang)
end
end
end
po:close()
GetText.current_lang = new_lang
end

@ -851,7 +851,8 @@ function Wikipedia:createEpub(epub_path, page, lang, with_images)
-- </guide>
local koreader_version = "KOReader"
if lfs.attributes("git-rev", "mode") == "file" then
koreader_version = "KOReader "..io.open("git-rev", "r"):read("*line")
local Version = require("version")
koreader_version = "KOReader " .. Version:getCurrentRevision()
end
local content_opf_parts = {}
-- head

@ -226,6 +226,11 @@ fi
# c.f., https://stackoverflow.com/a/37939589
version() { echo "$@" | awk -F. '{ printf("%d%03d%03d\n", $1,$2,$3); }'; }
# Detect kernels w/ CLOEXEC support
if [ "$(version "$(uname -r | sed -n -r 's/^([[:digit:]\.]*)(.*?)$/\1/p')")" -lt "$(version "2.6.23")" ]; then
export KINDLE_LEGACY="yes"
fi
# There's no pillow if we stopped the framework, and it's only there on systems with upstart anyway
if [ "${STOP_FRAMEWORK}" = "no" ] && [ "${INIT_TYPE}" = "upstart" ]; then
# NOTE: If we were launched from KUAL, don't even try to deal with KPVBooklet-specific workarounds

@ -85,6 +85,7 @@ function MyClipping:parseMyClippings()
end
index = index + 1
end
file:close()
end
return clippings

@ -58,6 +58,7 @@ local function parsePluginJson(filename)
local file, err = io.open(jsonPath, "r")
if file then
local contents = file:read("*all")
file:close()
local ok, parsed = pcall(JSON.decode, contents)
if ok then
return parsed

@ -454,6 +454,7 @@ function ReaderStatistics:partialMd5(file)
break
end
end
file_handle:close()
return update()
end

@ -245,7 +245,7 @@ function Terminal:killShell(ask)
return -1
end
local pid = tonumber(pid_file:read("*a"))
local pid = pid_file:read("*n")
pid_file:close()
if ask then

Loading…
Cancel
Save