Commit e5bc9f9a authored by Boleslav Březovský's avatar Boleslav Březovský

SLURP function renamed to READ_FILE for better readability

parent 6d6afcaa
......@@ -35,7 +35,7 @@ local run_util = run_util
module "utils"
-- luacheck: globals lines2set map set2arr arr2set cleanup_dirs slurp clone shallow_copy table_merge arr_append exception multi_index private filter_best strip table_overlay randstr arr_prune arr_inv file_exists
-- luacheck: globals lines2set map set2arr arr2set cleanup_dirs read_file clone shallow_copy table_merge arr_append exception multi_index private filter_best strip table_overlay randstr arr_prune arr_inv file_exists
--[[
Convert provided text into set of lines. Doesn't care about the order.
......@@ -116,7 +116,7 @@ end
Read the whole content of given file. Return the content, or nil and error message.
In case of errors during the reading (instead of when opening), it calls error()
]]
function slurp(filename)
function read_file(filename)
local f, err = io.open(filename)
if not f then
return nil, err
......
......@@ -296,7 +296,7 @@ end
-- Get pkg_name's file's content with given suffix. Nil on error.
local function pkg_file(pkg_name, suffix, _)
local fname = info_dir .. pkg_name .. "." .. suffix
local content, err = utils.slurp(fname)
local content, err = utils.read_file(fname)
if not content then
WARN("Could not read ." .. suffix .. " file of " .. pkg_name .. ": " .. err)
end
......@@ -531,7 +531,7 @@ function pkg_examine(dir)
end
conffiles = slashes_sanitize(conffiles)
-- Load the control file of the package and parse it
local control = package_postprocess(block_parse(utils.slurp(control_dir .. "/control")));
local control = package_postprocess(block_parse(utils.read_file(control_dir .. "/control")));
-- Wait for all asynchronous processes to finish
events_wait(unpack(events))
-- How well did it go?
......
......@@ -430,7 +430,7 @@ end
-- Queue a request to install a package from the given file name.
function queue_install(filename)
local content, err = utils.slurp(filename)
local content, err = utils.read_file(filename)
if content then
table.insert(queue, {op = "install", data = content})
else
......
......@@ -122,7 +122,7 @@ local function handler_file(uri, err_cback, done_cback)
if not ok then
return err_cback(utils.exception("malformed URI", "Bad URL encoding"))
end
local ok, content, err = pcall(utils.slurp, fname)
local ok, content, err = pcall(utils.read_file, fname)
if (not ok) or (not content) then
return err_cback(utils.exception("unreachable", tostring(content or err)))
end
......
......@@ -239,9 +239,9 @@ function load_state_vars()
]]
state_vars = {
root_dir = backend.root_dir,
model = utils.strip(utils.slurp('/tmp/sysinfo/model')),
board_name = utils.strip(utils.slurp('/tmp/sysinfo/board_name')),
turris_version = utils.strip(utils.slurp('/etc/turris-version')),
model = utils.strip(utils.read_file('/tmp/sysinfo/model')),
board_name = utils.strip(utils.read_file('/tmp/sysinfo/board_name')),
turris_version = utils.strip(utils.read_file('/etc/turris-version')),
self_version = get_updater_version(),
language_version = 1,
features = updater_features,
......@@ -250,7 +250,7 @@ function load_state_vars()
an empty string, which produces nil ‒ the element won't be in there.
We don't have a better fallback for platforms we don't know for now.
]]
architectures = {'all', (utils.slurp('/etc/openwrt_release') or ""):match("DISTRIB_TARGET='([^'/]*)")},
architectures = {'all', (utils.read_file('/etc/openwrt_release') or ""):match("DISTRIB_TARGET='([^'/]*)")},
installed = utils.map(status, function (name, pkg)
if utils.multi_index(pkg, "Status", 3) == "installed" then
return name, {
......
......@@ -252,7 +252,7 @@ local tmp_dirs = {}
Test the chain of functions ‒ unpack, examine
]]
function test_pkg_unpack()
local path = B.pkg_unpack(utils.slurp(datadir .. "updater.ipk"))
local path = B.pkg_unpack(utils.read_file(datadir .. "updater.ipk"))
-- Make sure it is deleted on teardown
table.insert(tmp_dirs, path)
-- Check list of extracted files
......@@ -851,8 +851,8 @@ function test_merge_control()
B.pkg_merge_control(src_dir, "pkg1", { file = true })
-- The files are in the destination directory with the right content
assert_table_equal({["pkg1.control"] = 'r', ["pkg1.list"] = 'r'}, ls(dst_dir))
assert_equal("test\n", utils.slurp(dst_dir .. "/pkg1.control"))
assert_equal("file\n", utils.slurp(dst_dir .. "/pkg1.list"))
assert_equal("test\n", utils.read_file(dst_dir .. "/pkg1.control"))
assert_equal("file\n", utils.read_file(dst_dir .. "/pkg1.list"))
-- The file stayed at the origin as well
assert_table_equal({["control"] = 'r'}, ls(src_dir))
end
......
......@@ -125,7 +125,7 @@ function test_recover_broken()
J.write(J.UNPACKED, { data = "xyz" }, { "x", "y", "z" })
J.finish(true)
-- Now damage the file a little bit
local content = utils.slurp(dir .. '/journal')
local content = utils.read_file(dir .. '/journal')
local f, err = io.open(dir .. '/journal', "w")
assert(f, err)
-- Store everything except for the last 3 bytes. That should kill the last FINISH record
......
......@@ -146,7 +146,7 @@ end
function test_get_repos_gzip()
local datadir = (os.getenv("S") or ".") .. "/tests/data"
local content = utils.slurp(datadir .. "/Packages.gz")
local content = utils.read_file(datadir .. "/Packages.gz")
requests.known_repositories_all = {repo_fake("test1", "http://example.org/test1", true, content)}
assert_nil(postprocess.get_repos())
assert_table_equal(example_output, requests.known_repositories_all)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment