diff options
-rw-r--r-- | debian/changelog | 2 | ||||
-rw-r--r-- | man/dpkg-divert.man | 22 | ||||
-rw-r--r-- | man/dpkg-statoverride.man | 24 | ||||
-rw-r--r-- | man/dpkg.man | 16 | ||||
-rw-r--r-- | src/divertcmd.c | 27 | ||||
-rw-r--r-- | src/main.c | 12 | ||||
-rw-r--r-- | src/statcmd.c | 32 |
7 files changed, 107 insertions, 28 deletions
diff --git a/debian/changelog b/debian/changelog index 6f9e4a0a6..52a48cc4c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -3,6 +3,8 @@ dpkg (1.19.2) UNRELEASED; urgency=medium [ Guillem Jover ] * dpkg: Fix --force-not-root for chown() and chmod() based syscalls, and give a more meaningful error message on chroot(). Closes: #614126 + * dpkg-divert, dpkg-statoverride: Add new --instdir and --root options, + and make the commands honor the DPKG_ROOT environment variable. * Perl modules: - Dpkg::OpenPGP: Ignore Version field in enarmored output. Fixes CPAN#127217. diff --git a/man/dpkg-divert.man b/man/dpkg-divert.man index 8631c20f5..cdd283b9a 100644 --- a/man/dpkg-divert.man +++ b/man/dpkg-divert.man @@ -66,8 +66,17 @@ Print the real name for a diverted file. .SH OPTIONS .TP .BI \-\-admindir " directory" -Set the \fBdpkg\fP data directory to \fIdirectory\fP (default: -\fI%ADMINDIR%\fP). +Set the administrative directory to \fIdirectory\fP. +Defaults to «\fI%ADMINDIR%\fP». +.TP +.BI \-\-instdir " directory" +Set the installation directory, which refers to the directory where +packages get installed (since dpkg 1.19.2). Defaults to «\fI/\fP». +.TP +.BI \-\-root " directory" +Set the root directory to \fBdirectory\fP, which sets the installation +directory to «\fIdirectory\fP» and the administrative +directory to «\fIdirectory\fP\fB%ADMINDIR%\fP» (since dpkg 1.19.2). .TP .BI \-\-divert " divert-to" \fIdivert-to\fP is the location where the versions of \fIfile\fP, as @@ -122,9 +131,14 @@ memory allocations, etc. . .SH ENVIRONMENT .TP +.B DPKG_ROOT +If set and the \fB\-\-instdir\fP or \fB\-\-root\fP options have not been +specified, it will be used as the filesystem root directory +(since dpkg 1.19.2). +.TP .B DPKG_ADMINDIR -If set and the \fB\-\-admindir\fP option has not been specified, it will -be used as the \fBdpkg\fP data directory. +If set and the \fB\-\-admindir\fP or \fB\-\-root\fP options have not been +specified, it will be used as the \fBdpkg\fP data directory. .TP .B DPKG_MAINTSCRIPT_PACKAGE If set and the \fB\-\-local\fP and \fB\-\-package\fP options have not been diff --git a/man/dpkg-statoverride.man b/man/dpkg-statoverride.man index 800801683..861d53bb7 100644 --- a/man/dpkg-statoverride.man +++ b/man/dpkg-statoverride.man @@ -70,8 +70,19 @@ Show the version and exit. .SH OPTIONS .TP .BI \-\-admindir " directory" -Change the \fIdirectory\fP of the \fBdpkg\fP database where the statoverride -file is also stored. Defaults to \fI%ADMINDIR%\fP. +Set the administrative directory to \fIdirectory\fP. +This is where the \fIstatoverride\fP file is stored. +Defaults to «\fI%ADMINDIR%\fP». +.TP +.BI \-\-instdir " directory" +Set the installation directory, which refers to the directory where +packages get installed (since dpkg 1.19.2). +Defaults to «\fI/\fP». +.TP +.BI \-\-root " directory" +Set the root directory to \fBdirectory\fP, which sets the installation +directory to «\fIdirectory\fP» and the administrative +directory to «\fIdirectory\fP\fB%ADMINDIR%\fP» (since dpkg 1.19.2). .TP .B \-\-force Force an action, even if a sanity check would otherwise prohibit it. @@ -100,9 +111,14 @@ memory allocations, etc. . .SH ENVIRONMENT .TP +.B DPKG_ROOT +If set and the \fB\-\-instdir\fP or \fB\-\-root\fP options have not been +specified, it will be used as the filesystem root directory +(since dpkg 1.19.2). +.TP .B DPKG_ADMINDIR -If set and the \fB\-\-admindir\fP option has not been specified, it will -be used as the \fBdpkg\fP data directory. +If set and the \fB\-\-admindir\fP or \fB\-\-root\fP options have not been +specified, it will be used as the \fBdpkg\fP data directory. .TP .B DPKG_COLORS Sets the color mode (since dpkg 1.18.5). diff --git a/man/dpkg.man b/man/dpkg.man index 588a21746..eff9d6667 100644 --- a/man/dpkg.man +++ b/man/dpkg.man @@ -674,20 +674,22 @@ Don't install a package if a newer version of the same package is already installed. This is an alias of \fB\-\-refuse\-downgrade\fP. .TP .BI \-\-admindir= dir -Change default administrative directory, which contains many files that -give information about status of installed or uninstalled packages, etc. -(Defaults to «\fI%ADMINDIR%\fP») +Set the administrative directory to \fIdirectory\fP. +This directory contains many files that give information about status of +installed or uninstalled packages, etc. +Defaults to «\fI%ADMINDIR%\fP». .TP .BI \-\-instdir= dir -Change default installation directory which refers to the directory where +Set the installation directory, which refers to the directory where packages are to be installed. \fBinstdir\fP is also the directory passed to \fBchroot\fP(2) before running package's installation scripts, which means that the scripts see \fBinstdir\fP as a root directory. -(Defaults to «\fI/\fP») +Defaults to «\fI/\fP». .TP .BI \-\-root= dir -Changing \fBroot\fP changes \fBinstdir\fP to «\fIdir\fP» and -\fBadmindir\fP to «\fIdir\fP\fB%ADMINDIR%\fP». +Set the root directory to \fBdirectory\fP, which sets the installation +directory to «\fIdir\fP» and the administrative +directory to «\fIdir\fP\fB%ADMINDIR%\fP». .TP \fB\-O\fP, \fB\-\-selected\-only\fP Only process the packages that are selected for installation. The diff --git a/src/divertcmd.c b/src/divertcmd.c index 69d187c45..8e7b66eeb 100644 --- a/src/divertcmd.c +++ b/src/divertcmd.c @@ -52,6 +52,7 @@ static const char printforhelp[] = N_( "Use --help for help about diverting files."); static const char *admindir; +const char *instdir; static bool opt_pkgname_match_any = true; static const char *opt_pkgname = NULL; @@ -102,6 +103,8 @@ usage(const struct cmdinfo *cip, const char *value) " --rename actually move the file aside (or back).\n" " --no-rename do not move the file aside (or back) (default).\n" " --admindir <directory> set the directory with the diversions file.\n" +" --instdir <directory> set the root directory, but not the admin dir.\n" +" --root <directory> set the directory of the root filesystem.\n" " --test don't do anything, just demonstrate.\n" " --quiet quiet operation, minimal output.\n" " --help show this help message.\n" @@ -142,7 +145,13 @@ struct file { static void file_init(struct file *f, const char *filename) { - f->name = filename; + struct varbuf usefilename = VARBUF_INIT; + + varbuf_add_str(&usefilename, instdir); + varbuf_add_str(&usefilename, filename); + varbuf_end_str(&usefilename); + + f->name = varbuf_detach(&usefilename); f->stat_state = FILE_STAT_INVALID; } @@ -779,6 +788,19 @@ set_divertto(const struct cmdinfo *cip, const char *value) badusage(_("divert-to may not contain newlines")); } +static void +set_instdir(const struct cmdinfo *cip, const char *value) +{ + instdir = dpkg_fsys_set_dir(value); +} + +static void +set_root(const struct cmdinfo *cip, const char *value) +{ + instdir = dpkg_fsys_set_dir(value); + admindir = dpkg_fsys_get_path(ADMINDIR); +} + static const struct cmdinfo cmdinfo_add = ACTION("add", 0, 0, diversion_add); @@ -790,6 +812,8 @@ static const struct cmdinfo cmdinfos[] = { ACTION("truename", 0, 0, diversion_truename), { "admindir", 0, 1, NULL, &admindir, NULL }, + { "instdir", 0, 1, NULL, NULL, set_instdir, 0 }, + { "root", 0, 1, NULL, NULL, set_root, 0 }, { "divert", 0, 1, NULL, NULL, set_divertto }, { "package", 0, 1, NULL, NULL, set_package }, { "local", 0, 0, NULL, NULL, set_package }, @@ -813,6 +837,7 @@ main(int argc, const char * const *argv) dpkg_options_parse(&argv, cmdinfos, printforhelp); admindir = dpkg_db_set_dir(admindir); + instdir = dpkg_fsys_set_dir(instdir); env_pkgname = getenv("DPKG_MAINTSCRIPT_PACKAGE"); if (opt_pkgname_match_any && env_pkgname) diff --git a/src/main.c b/src/main.c index c1276c96d..adaff0326 100644 --- a/src/main.c +++ b/src/main.c @@ -46,7 +46,6 @@ #include <dpkg/dpkg.h> #include <dpkg/dpkg-db.h> #include <dpkg/arch.h> -#include <dpkg/path.h> #include <dpkg/subproc.h> #include <dpkg/command.h> #include <dpkg/options.h> @@ -357,19 +356,14 @@ set_verify_format(const struct cmdinfo *cip, const char *value) static void set_instdir(const struct cmdinfo *cip, const char *value) { - char *new_instdir; - - new_instdir = m_strdup(value); - path_trim_slash_slashdot(new_instdir); - - instdir = new_instdir; + instdir = dpkg_fsys_set_dir(value); } static void set_root(const struct cmdinfo *cip, const char *value) { - set_instdir(cip, value); - admindir = str_fmt("%s%s", instdir, ADMINDIR); + instdir = dpkg_fsys_set_dir(value); + admindir = dpkg_fsys_get_path(ADMINDIR); } static void diff --git a/src/statcmd.c b/src/statcmd.c index b7ca09eeb..741b50000 100644 --- a/src/statcmd.c +++ b/src/statcmd.c @@ -84,6 +84,8 @@ usage(const struct cmdinfo *cip, const char *value) printf(_( "Options:\n" " --admindir <directory> set the directory with the statoverride file.\n" +" --instdir <directory> set the root directory, but not the admin dir.\n" +" --root <directory> set the directory of the root filesystem.\n" " --update immediately update <path> permissions.\n" " --force force an action even if a sanity check fails.\n" " --quiet quiet operation, minimal output.\n" @@ -97,11 +99,25 @@ usage(const struct cmdinfo *cip, const char *value) } static const char *admindir; +const char *instdir; static int opt_verbose = 1; static int opt_force = 0; static int opt_update = 0; +static void +set_instdir(const struct cmdinfo *cip, const char *value) +{ + instdir = dpkg_fsys_set_dir(value); +} + +static void +set_root(const struct cmdinfo *cip, const char *value) +{ + instdir = dpkg_fsys_set_dir(value); + admindir = dpkg_fsys_get_path(ADMINDIR); +} + static char * path_cleanup(const char *path) { @@ -260,14 +276,21 @@ statoverride_add(const char *const *argv) if (opt_update) { struct stat st; + struct varbuf realfilename = VARBUF_INIT; + + varbuf_add_str(&realfilename, instdir); + varbuf_add_str(&realfilename, filename); + varbuf_end_str(&realfilename); - if (stat(filename, &st) == 0) { + if (stat(realfilename.buf, &st) == 0) { (*filestat)->mode |= st.st_mode & S_IFMT; - statdb_node_apply(filename, *filestat); + statdb_node_apply(realfilename.buf, *filestat); } else if (opt_verbose) { warning(_("--update given but %s does not exist"), - filename); + realfilename.buf); } + + varbuf_destroy(&realfilename); } statdb_write(); @@ -349,6 +372,8 @@ static const struct cmdinfo cmdinfos[] = { ACTION("list", 0, act_listfiles, statoverride_list), { "admindir", 0, 1, NULL, &admindir, NULL }, + { "instdir", 0, 1, NULL, NULL, set_instdir, 0 }, + { "root", 0, 1, NULL, NULL, set_root, 0 }, { "quiet", 0, 0, &opt_verbose, NULL, NULL, 0 }, { "force", 0, 0, &opt_force, NULL, NULL, 1 }, { "update", 0, 0, &opt_update, NULL, NULL, 1 }, @@ -367,6 +392,7 @@ main(int argc, const char *const *argv) dpkg_options_parse(&argv, cmdinfos, printforhelp); admindir = dpkg_db_set_dir(admindir); + instdir = dpkg_fsys_set_dir(instdir); if (!cipaction) badusage(_("need an action option")); |