This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch main
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=60c96ae45bf6c0e21c7b1176e56d546a4a66f818

commit 60c96ae45bf6c0e21c7b1176e56d546a4a66f818 (HEAD -> main)
Author: Guillem Jover <[email protected]>
AuthorDate: Sat Jun 26 23:12:19 2021 +0200

    dpkg-query, dpkg-trigger, dselect: Add support for setting the root 
directory
    
    This adds both a --root option, and DPKG_ROOT environment variable
    support.
---
 dselect/main.cc      | 14 +++++++++++++-
 man/dpkg-query.pod   | 10 ++++++++++
 man/dpkg-trigger.pod | 10 ++++++++++
 man/dselect.pod      | 10 ++++++++++
 src/querycmd.c       | 17 ++++++++++++++---
 src/trigcmd.c        | 13 ++++++++++++-
 6 files changed, 69 insertions(+), 5 deletions(-)

diff --git a/dselect/main.cc b/dselect/main.cc
index 9166c0393..89432257a 100644
--- a/dselect/main.cc
+++ b/dselect/main.cc
@@ -54,6 +54,7 @@
 #include <dpkg/dpkg.h>
 #include <dpkg/dpkg-db.h>
 #include <dpkg/options.h>
+#include <dpkg/fsys.h>
 
 #include "dselect.h"
 #include "bindings.h"
@@ -64,6 +65,7 @@ static const char printforhelp[] = N_("Type dselect --help 
for help.");
 bool expertmode = false;
 
 static const char *admindir;
+static const char *instdir;
 
 static keybindings 
packagelistbindings(packagelist_kinterps,packagelist_korgbindings);
 
@@ -187,11 +189,12 @@ usage(const struct cmdinfo *ci, const char *value)
   printf(_(
 "Options:\n"
 "      --admindir <directory>       Use <directory> instead of %s.\n"
+"      --root <directory>           Use <directory> instead of %s.\n"
 "      --expert                     Turn on expert mode.\n"
 "  -D, --debug <file>               Turn on debugging, send output to 
<file>.\n"
 "      --color <color-spec>         Configure screen colors.\n"
 "      --colour <color-spec>        Ditto.\n"
-), ADMINDIR);
+), ADMINDIR, "/");
 
   printf(_(
 "  -?, --help                       Show this help message.\n"
@@ -223,6 +226,13 @@ usage(const struct cmdinfo *ci, const char *value)
 /* These are called by C code, so need to have C calling convention */
 extern "C" {
 
+  static void
+  set_root(const struct cmdinfo*, const char *v)
+  {
+    instdir = dpkg_fsys_set_dir(v);
+    admindir = dpkg_fsys_get_path(ADMINDIR);
+  }
+
   static void
   set_debug(const struct cmdinfo*, const char *v)
   {
@@ -312,6 +322,7 @@ extern "C" {
 
 static const struct cmdinfo cmdinfos[]= {
   { "admindir",     0,  1, nullptr,  &admindir, nullptr      },
+  { "root",         0,  1, nullptr,  nullptr,   set_root, 1  },
   { "debug",       'D', 1, nullptr,  nullptr,   set_debug    },
   { "expert",      'E', 0, nullptr,  nullptr,   set_expert   },
   { "help",        '?', 0, nullptr,  nullptr,   usage        },
@@ -531,6 +542,7 @@ main(int, const char *const *argv)
   dpkg_options_load(DSELECT, cmdinfos);
   dpkg_options_parse(&argv, cmdinfos, printforhelp);
 
+  instdir = dpkg_fsys_set_dir(instdir);
   admindir = dpkg_db_set_dir(admindir);
 
   if (*argv) {
diff --git a/man/dpkg-query.pod b/man/dpkg-query.pod
index 0b9b83f09..3809ace09 100644
--- a/man/dpkg-query.pod
+++ b/man/dpkg-query.pod
@@ -231,6 +231,11 @@ Show the version and exit.
 Change the location of the B<dpkg> database. The default location is
 I<%ADMINDIR%>.
 
+=item B<--root=>I<directory>
+
+Set the root directory to I<directory>, which sets the administrative
+directory to «I<directory>%ADMINDIR%» (since dpkg 1.21.0).
+
 =item B<--load-avail>
 
 Also load the available file when using the B<--show> and B<--list>
@@ -472,6 +477,11 @@ If B<SHELL> is not set, «B<sh>» will be used instead.
 The B<DPKG_PAGER> overrides the B<PAGER> environment variable
 (since dpkg 1.19.2).
 
+=item B<DPKG_ROOT>
+
+If set and the B<--root> option has not been specified, it will
+be used as the filesystem root directory (since dpkg 1.21.0).
+
 =item B<DPKG_ADMINDIR>
 
 If set and the B<--admindir> option has not been specified, it will
diff --git a/man/dpkg-trigger.pod b/man/dpkg-trigger.pod
index 670550451..17d3aaf8b 100644
--- a/man/dpkg-trigger.pod
+++ b/man/dpkg-trigger.pod
@@ -72,6 +72,11 @@ Show the version and exit.
 Change the location of the B<dpkg> database. The default location is
 I<%ADMINDIR%>.
 
+=item B<--root=>I<directory>
+
+Set the root directory to I<directory>, which sets the administrative
+directory to «I<directory>%ADMINDIR%» (since dpkg 1.21.0).
+
 =item B<--by-package=>I<package>
 
 Override trigger awaiter (normally set by B<dpkg> through the
@@ -125,6 +130,11 @@ memory allocations, etc.
 
 =over
 
+=item B<DPKG_ROOT>
+
+If set and the B<--root> option has not been specified, it will be used as
+the filesystem root directory (since dpkg 1.21.0).
+
 =item B<DPKG_ADMINDIR>
 
 If set and the B<--admindir> option has not been specified, it will
diff --git a/man/dselect.pod b/man/dselect.pod
index 2bc5471ed..609782f31 100644
--- a/man/dselect.pod
+++ b/man/dselect.pod
@@ -92,6 +92,11 @@ Changes the directory where the dpkg ‘I<status>’,
 This defaults to I<%ADMINDIR%>
 and normally there shouldn't be any need to change it.
 
+=item B<--root> I<directory>
+
+Set the root directory to I<directory>, which sets the administrative
+directory to «I<directory>%ADMINDIR%» (since dpkg 1.21.0).
+
 =item B<-D>I<file>, B<--debug> I<file>
 
 Turn on debugging. Debugging information is sent to I<file>.
@@ -622,6 +627,11 @@ memory allocations, etc.
 
 =over
 
+=item B<DPKG_ROOT>
+
+If set and the B<--root> option has not been specified, it will
+be used as the filesystem root directory (since dpkg 1.21.0).
+
 =item B<DPKG_ADMINDIR>
 
 If set and the B<--admindir> option has not been specified, it will
diff --git a/src/querycmd.c b/src/querycmd.c
index 1c1b56c2a..6e3fe51ef 100644
--- a/src/querycmd.c
+++ b/src/querycmd.c
@@ -58,6 +58,9 @@
 
 #include "actions.h"
 
+static const char *admindir;
+static const char *instdir;
+
 static const char *showformat = "${binary:Package}\t${Version}\n";
 
 static int opt_loadavail = 0;
@@ -762,6 +765,13 @@ control_show(const char *const *argv)
   return 0;
 }
 
+static void
+set_root(const struct cmdinfo *cip, const char *value)
+{
+  instdir = dpkg_fsys_set_dir(value);
+  admindir = dpkg_fsys_get_path(ADMINDIR);
+}
+
 static void
 set_no_pager(const struct cmdinfo *ci, const char *value)
 {
@@ -812,10 +822,11 @@ usage(const struct cmdinfo *ci, const char *value)
   printf(_(
 "Options:\n"
 "  --admindir=<directory>           Use <directory> instead of %s.\n"
+"  --root=<directory>               Use <directory> instead of %s.\n"
 "  --load-avail                     Use available file on --show and --list.\n"
 "  --no-pager                       Disables the use of any pager.\n"
 "  -f|--showformat=<format>         Use alternative format for --show.\n"
-"\n"), ADMINDIR);
+"\n"), ADMINDIR, "/");
 
   printf(_(
 "Format syntax:\n"
@@ -834,8 +845,6 @@ usage(const struct cmdinfo *ci, const char *value)
 static const char printforhelp[] = N_(
 "Use --help for help about querying packages.");
 
-static const char *admindir;
-
 /* This table has both the action entries in it and the normal options.
  * The action entries are made with the ACTION macro, as they all
  * have a very similar structure. */
@@ -851,6 +860,7 @@ static const struct cmdinfo cmdinfos[]= {
   ACTION( "control-show",                    0,  act_controlshow,   
control_show    ),
 
   { "admindir",   0,   1, NULL, &admindir,   NULL          },
+  { "root",       0,   1, NULL, NULL,        set_root, 0   },
   { "load-avail", 0,   0, &opt_loadavail, NULL, NULL, 1    },
   { "showformat", 'f', 1, NULL, &showformat, NULL          },
   { "no-pager",   0,   0, NULL, NULL,        set_no_pager  },
@@ -867,6 +877,7 @@ int main(int argc, const char *const *argv) {
   dpkg_program_init("dpkg-query");
   dpkg_options_parse(&argv, cmdinfos, printforhelp);
 
+  instdir = dpkg_fsys_set_dir(instdir);
   admindir = dpkg_db_set_dir(admindir);
 
   if (!cipaction) badusage(_("need an action option"));
diff --git a/src/trigcmd.c b/src/trigcmd.c
index e36d115a8..e7d589644 100644
--- a/src/trigcmd.c
+++ b/src/trigcmd.c
@@ -80,12 +80,13 @@ usage(const struct cmdinfo *ci, const char *value)
        printf(_(
 "Options:\n"
 "  --admindir=<directory>           Use <directory> instead of %s.\n"
+"  --root=<directory>               Use <directory> instead of %s.\n"
 "  --by-package=<package>           Override trigger awaiter (normally set\n"
 "                                     by dpkg).\n"
 "  --await                          Package needs to await the processing.\n"
 "  --no-await                       No package needs to await the 
processing.\n"
 "  --no-act                         Just test - don't actually change 
anything.\n"
-"\n"), ADMINDIR);
+"\n"), ADMINDIR, "/");
 
        m_output(stdout, _("<standard output>"));
 
@@ -93,12 +94,20 @@ usage(const struct cmdinfo *ci, const char *value)
 }
 
 static const char *admindir;
+static const char *instdir;
 static int f_noact, f_check;
 static int f_await = 1;
 
 static const char *bypackage, *activate;
 static bool done_trig, ctrig;
 
+static void
+set_root(const struct cmdinfo *cip, const char *value)
+{
+       instdir = dpkg_fsys_set_dir(value);
+       admindir = dpkg_fsys_get_path(ADMINDIR);
+}
+
 static void
 yespackage(const char *awname)
 {
@@ -191,6 +200,7 @@ do_check(void)
 
 static const struct cmdinfo cmdinfos[] = {
        { "admindir",        0,   1, NULL,     &admindir },
+       { "root",            0,   1, NULL,     NULL,       set_root, 0 },
        { "by-package",      'f', 1, NULL,     &bypackage },
        { "await",           0,   0, &f_await, NULL,       NULL, 1 },
        { "no-await",        0,   0, &f_await, NULL,       NULL, 0 },
@@ -212,6 +222,7 @@ main(int argc, const char *const *argv)
        dpkg_program_init("dpkg-trigger");
        dpkg_options_parse(&argv, cmdinfos, printforhelp);
 
+       instdir = dpkg_fsys_set_dir(instdir);
        admindir = dpkg_db_set_dir(admindir);
 
        if (f_check) {

-- 
Dpkg.Org's dpkg

Reply via email to