Commit 1564ebf8 authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner

pkg: Fix for getting lists of files

parent d3e03897
......@@ -31,11 +31,10 @@ local run_command = run_command
local events_wait = events_wait
local DBG = DBG
local WARN = WARN
local utils = require "utils"
module "backend"
require "utils"
--[[
Configuration of the module. It is supported (yet unlikely to be
needed) to modify these variables.
......@@ -348,13 +347,13 @@ function pkg_examine(dir)
Split into „lines“ separated by 0-char. Then eat leading dots and, in case
there was only a dot, replace it by /.
]]
return utils.map(utils.lines2set(text, "%z"), function (f) return f:gsub("^%.", ""):gsub("^$", "/") end)
return utils.map(utils.lines2set(text, "%z"), function (f) return f:gsub("^%.", ""):gsub("^$", "/"), true end)
end
local files, dirs
-- One for non-directories
launch(data_dir, function (text) files = find_result(text) end, "find", "!", "-type", "d", "-print0")
launch(data_dir, function (text) files = find_result(text) end, "/usr/bin/find", "!", "-type", "d", "-print0")
-- One for directories
launch(data_dir, function (text) dirs = find_result(text) end, "find", "-type", "d", "-print0")
launch(data_dir, function (text) dirs = find_result(text) end, "/usr/bin/find", "-type", "d", "-print0")
-- Wait for all asynchronous processes to finish
events_wait(unpack(events))
-- How well did it go?
......
......@@ -25,6 +25,8 @@ local lines2set = utils.lines2set
module("backend-tests", package.seeall, lunit.testcase)
local datadir = (os.getenv("S") or ".") .. "/tests/data/"
-- Tests for the block_parse function
function test_block_parse()
-- Simple case
......@@ -236,8 +238,11 @@ local orig_status_file = B.status_file
local orig_info_dir = B.info_dir
local tmp_dirs = {}
--[[
Test the chain of functions ‒ unpack, examine
]]
function test_pkg_unpack()
local fname = (os.getenv("S") or ".") .. "/tests/data/updater.ipk"
local fname = datadir .. "updater.ipk"
local f = io.open(fname)
local input = f:read("*a")
f:close()
......@@ -277,7 +282,31 @@ function test_pkg_unpack()
./data/usr/share/updater/keys/release.pem
./data/usr/share/updater/keys/standby.pem
]]), lines2set(stdout))
end, nil, nil, -1, -1, '/bin/sh', '-c', "cd '" .. path .. "' && find"))
end, function () chdir(path) end, nil, -1, -1, "/usr/bin/find"))
local files, dirs = B.pkg_examine(path)
assert_table_equal(lines2set([[/etc/init.d/updater
/etc/config/updater
/etc/ssl/updater.pem
/usr/share/updater/keys/standby.pem
/usr/share/updater/keys/release.pem
/usr/bin/updater-resume.sh
/usr/bin/updater.sh
/usr/bin/updater-unstuck.sh
/usr/bin/updater-utils.sh
/usr/bin/updater-worker.sh
/usr/bin/updater-wipe.sh]]), files)
assert_table_equal(lines2set([[/
/etc
/etc/init.d
/etc/cron.d
/etc/config
/etc/ssl
/usr
/usr/share
/usr/share/updater
/usr/share/updater/hashes
/usr/share/updater/keys
/usr/bin]]), dirs)
end
function setup()
......
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