opkg-trans: The -R flag

To set the root directory/prefix.
parent d95824f7
......@@ -42,6 +42,7 @@ local ls = ls
local DBG = DBG
local WARN = WARN
local utils = require "utils"
local journal = require "journal"
module "backend"
......@@ -50,18 +51,34 @@ Configuration of the module. It is supported (yet unlikely to be
needed) to modify these variables.
]]
-- The file with status of installed packages
status_file = "/usr/lib/opkg/status"
local status_file_suffix = "/usr/lib/opkg/status"
status_file = status_file_suffix
-- The directory where unpacked control files of the packages live
info_dir = "/usr/lib/opkg/info/"
local info_dir_suffix = "/usr/lib/opkg/info/"
info_dir = info_dir_suffix
-- A root directory
root_dir = "/"
-- A directory where unpacked packages live
pkg_temp_dir = "/usr/share/updater/unpacked"
local pkg_temp_dir_suffix = "/usr/share/updater/unpacked"
pkg_temp_dir = pkg_temp_dir_suffix
-- Time after which we SIGTERM external commands. Something incredibly long, just prevent them from being stuck.
cmd_timeout = 600000
-- Time after which we SIGKILL external commands
cmd_kill_timeout = 900000
--[[
Set all the configurable directories to be inside the provided dir
Effectively sets that the whole system is mounted under some
prefix.
]]
function root_dir_set(dir)
root_dir = dir .. "/"
status_file = dir .. status_file_suffix
info_dir = dir .. info_dir_suffix
pkg_temp_dir = dir .. pkg_temp_dir
journal.path = dir .. "/usr/share/updater/journal"
end
--[[
Parse a single block of mail-header-like records.
Return as a table.
......
......@@ -26,7 +26,7 @@
#include <stdio.h>
#include <assert.h>
const char *help =
static const char *help =
"opkg-trans -j Recover from a crash/reboot from a journal.\n"
"opkg-trans -b Abort interrupted work in the journal and clean.\n"
" up. Some stages of installation might not be\n"
......@@ -35,6 +35,7 @@ const char *help =
" (-a) need a path to already downloaded package\n"
" file. The ones to remove (-r) expect name of the\n"
" package.\n"
"opkg-trans -R /root/dir Use given path as a root directory\n"
"opkg-trans -h This help message.\n";
int main(int argc, char *argv[]) {
......@@ -71,6 +72,11 @@ int main(int argc, char *argv[]) {
#define NIP(TYPE) case COT_##TYPE: fputs("Operation " #TYPE " not implemented yet\n", stderr); return 1
NIP(JOURNAL_ABORT);
NIP(JOURNAL_RESUME);
case COT_ROOT_DIR: {
const char *err = interpreter_call(interpreter, "backend.root_dir_set", NULL, "s", op->parameter);
ASSERT_MSG(!err, "%s", err);
break;
}
default:
assert(0);
}
......
......@@ -654,6 +654,14 @@ PKG_ROOT=
assert_equal("test\n", stderr)
end
function test_root_dir_set()
B.root_dir_set("/dir")
assert_equal("/dir/usr/lib/opkg/status", B.status_file)
assert_equal("/dir/usr/lib/opkg/info/", B.info_dir)
assert_equal("/dir/usr/share/updater/unpacked", B.pkg_temp_dir)
assert_equal("/dir/usr/share/updater/journal", journal.path)
end
function setup()
local sdir = os.getenv("S") or "."
-- Use a shortened version of a real status file for tests
......
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