WIP

parent 7b2a8ce1
......@@ -27,6 +27,7 @@ local next = next
local tostring = tostring
local tonumber = tonumber
local assert = assert
local string = string
local unpack = unpack
local io = io
local os = os
......@@ -50,7 +51,8 @@ local sha256_file = sha256_file
-- local test_extract = test_extract
local extract_inner_archive = extract_inner_archive
local get_file_size = get_file_size
local get_file_content = get_file_content
local archive_read_file = archive_read_file
local archive_file_present = archive_file_present
local DBG = DBG
local WARN = WARN
local ERROR = ERROR
......@@ -452,6 +454,7 @@ TODO:
-- First we duplicate old functionality, to keep the rewrite simple
function pkg_unpack(package_path)
print("====================pkg_unpack: " .. package_path)
-- We do not need temp directory, so let's just use s2dir (renamed to just dir)
utils.mkdirp(syscnf.pkg_unpacked_dir)
......@@ -460,12 +463,15 @@ function pkg_unpack(package_path)
extract_inner_archive(package_path, "data", dir)
get_file_size(package_path, "control", "conffiles")
local fs = get_file_size(package_path, "control", "conffiles")
print("file_size:" .. fs)
local data = get_file_content(package_path, "control", "conffiles")
print("(((in Lua, data)))\n" .. data .. "---")
print("dir: " .. dir)
return dir
end
......@@ -538,7 +544,7 @@ In all three cases, the file names are keys, not values.
In case of errors, it raises error()
]]
function pkg_examine(dir)
function orig_pkg_examine(dir)
local data_dir = dir .. "/data"
-- Events to wait for
local events = {}
......@@ -570,6 +576,7 @@ function pkg_examine(dir)
-- Get list of config files, if there are any
local control_dir = dir .. "/control"
local cidx = io.open(control_dir .. "/conffiles")
-- BB: use extract_file_to_memory_here
local conffiles = {}
if cidx then
for l in cidx:lines() do
......@@ -601,6 +608,75 @@ function pkg_examine(dir)
return files, dirs, conffiles, control
end
function pkg_examine(package_path, dir)
local data_dir = dir .. "/data"
-- Events to wait for
local events = {}
local err = nil
-- Launch scans of the data directory
local function launch(postprocess, ...)
local function cback(ecode, _, stdout, stderr)
if ecode == 0 then
postprocess(stdout)
else
err = stderr
end
end
print("-------launch() called--------")
local event = run_util(cback, function () chdir(data_dir) end, nil, cmd_timeout, cmd_kill_timeout, ...)
table.insert(events, event)
end
local function find_result(text)
--[[
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("^$", "/"), true end)
end
local files, dirs
-- One for non-directories
launch(function (text) files = slashes_sanitize(find_result(text)) end, "find", "!", "-type", "d", "-print0")
-- One for directories
launch(function (text) dirs = slashes_sanitize(find_result(text)) end, "find", "-type", "d", "-print0")
-- Get list of config files, if there are any
local cidx = archive_read_file(package_path, "control", "conffiles")
print("BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n" .. cidx)
local conffiles = {}
if cidx then
for l in string.gmatch(cidx, "[^\n]+") do
local fname = l:match("^%s*(/.*%S)%s*")
if archive_file_present(package_path, "data", fname) then
conffiles[fname] = sha256(archive_read_file(package_path, "data", fname))
else
error("File " .. fname .. " does not exist.")
end
end
end
conffiles = slashes_sanitize(conffiles)
-- Load the control file of the package and parse it
local control = package_postprocess(block_parse(archive_read_file(package_path, "control", "control")))
-- Wait for all asynchronous processes to finish
events_wait(unpack(events))
-- How well did it go?
if err then
error(err)
end
-- Complete the control structure
control.files = files
if next(conffiles) then -- Don't store empty config files
control.Conffiles = conffiles
end
control["Installed-Time"] = tostring(os.time())
control.Status = {"install", "user", "installed"}
return files, dirs, conffiles, control
end
--[[
Check if we can perform installation of packages and no files
of other packages would get overwritten. It checks both the
......
......@@ -72,6 +72,7 @@ end
-- Stages of the transaction. Each one is written into the journal, with its results.
local function pkg_unpack(operations, status)
print("+++pkg_unpack+++")
update_state(LS_UNPACK)
INFO("Unpacking download packages")
local dir_cleanups = {}
......@@ -97,7 +98,9 @@ local function pkg_unpack(operations, status)
elseif op.op == "install" then
local pkg_dir = backend.pkg_unpack(op.file)
table.insert(dir_cleanups, pkg_dir)
local files, dirs, configs, control = backend.pkg_examine(pkg_dir)
-- local files, dirs, configs, control = backend.pkg_examine(pkg_dir)
print("xxx Calling pkg_examine(" .. op.file .. ", " .. pkg_dir .. ")")
local files, dirs, configs, control = backend.pkg_examine(op.file, pkg_dir)
to_remove[control.Package] = true
to_install[control.Package] = files
--[[
......
......@@ -656,7 +656,7 @@ static int lua_get_file_size(lua_State *L) {
return 1;
}
static int lua_get_file_content(lua_State *L) {
static int lua_archive_read_file(lua_State *L) {
const char *arc_name = luaL_checkstring(L, 1);
const char *subarc_name = luaL_checkstring(L, 2);
const char *path = luaL_checkstring(L, 3);
......@@ -671,6 +671,33 @@ static int lua_get_file_content(lua_State *L) {
return 1;
}
static int lua_archive_file_present(lua_State *L) {
const char *arc_name = luaL_checkstring(L, 1);
const char *subarc_name = luaL_checkstring(L, 2);
const char *path = luaL_checkstring(L, 3);
printf("lua_calling fpia\n");
int ret = archive_file_present(arc_name, subarc_name, path);
if (ret == 0) {
lua_pushboolean(L, 1);
} else {
lua_pushboolean(L, 0);
}
printf("returned: %d\n", ret);
return 1;
}
void l_pushtablestring(lua_State* L , char* key , char* value) {
lua_pushstring(L, key);
lua_pushstring(L, value);
lua_settable(L, -3);
}
static int lua_archive_list_files(lua_State *L) {
const char *arc_name = luaL_checkstring(L, 1);
const char *subarc_name = luaL_checkstring(L, 2);
printf("lua_archive_list_names");
lua_newtable(L);
l_pushtablestring(L,
}
static const char *stat2str(const struct stat *buf) {
switch (buf->st_mode & S_IFMT) {
case S_IFSOCK:
......@@ -955,7 +982,9 @@ static const struct injected_func injected_funcs[] = {
{ lua_copy, "copy" },
{ lua_extract_inner_archive, "extract_inner_archive" },
{ lua_get_file_size, "get_file_size" },
{ lua_get_file_content, "get_file_content" },
{ lua_archive_read_file, "archive_read_file" },
{ lua_archive_file_present, "archive_file_present" },
{ lua_archive_list_files, "archive_list_files" },
{ lua_ls, "ls" },
{ lua_stat, "stat" },
{ lua_lstat, "lstat" },
......
......@@ -37,8 +37,14 @@ static char * sanitize_filename(char *dst, const char *src) {
int r;
r = strncmp("./", src, 2);
if (r != 0) {
strcpy(dst, "./");
strcat(dst, src);
r = strncmp("/", src, 1);
if (r != 0) {
strcpy(dst, "./");
strcat(dst, src);
} else {
strcpy(dst, ".");
strcat(dst, src);
}
} else {
strcpy(dst, src);
}
......@@ -335,6 +341,18 @@ int get_file_size(const char *arcname, const char *subarcname, const char *filen
return process_file(arcname, subarcname, filename, get_size);
}
int archive_file_present(const char *arcname, const char *subarcname, const char *filename) {
int ret = -1;
printf("[[[FPIA]]] top: %s\n", filename);
int file_present(struct archive *a, struct archive_entry *entry) {
printf("[[[FPIA]]]\nentry: %s\nfilen: %s\n", archive_entry_pathname(entry), filename);
ret = 0;
return 0;
}
process_file(arcname, subarcname, filename, file_present);
return ret;
}
/* extract file into current directory (TODO: add path?) */
int extract_file_to_disk(const char *arcname, const char *subarcname, const char *filename) {
int unpack(struct archive *a, struct archive_entry *entry) {
......
......@@ -25,4 +25,4 @@ int get_file_size(const char *arcname, const char *subarcname, const char *filen
int extract_file_to_memory(char *buff, const char *arcname, const char *subarcname, const char *filename, int size);
int test_extract(const char *arc_name, const char *subarc_name, char *files[], int count);
int archive_file_present(const char *arcname, const char *subarcname, const char *filename);
......@@ -298,7 +298,7 @@ function test_pkg_unpack()
./data/usr/share/updater/keys/standby.pem
]]), lines2set(stdout))
end, function () chdir(path) end, nil, -1, -1, "/usr/bin/find"))
local files, dirs, conffiles, control = B.pkg_examine(path)
local files, dirs, conffiles, control = B.pkg_examine(datadir .. "updater.ipk", path)
assert_table_equal(lines2set(
[[
/etc/init.d/updater
......
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