The following commit has been merged in the master branch:
commit 9a98858f89ca4753182aa4682738d035c69e62ee
Author: Guillem Jover <[email protected]>
Date: Sun Dec 2 21:42:14 2012 +0100
dpkg-deb: Use an enum instead of a literal string to pass tar options
This clarifies the call sites as to what they want from the extractor,
and abstracts the code to allow for a future switch to an internal tar
extractor instead of requiring an external tar program.
diff --git a/dpkg-deb/dpkg-deb.h b/dpkg-deb/dpkg-deb.h
index 30ed306..1c470cb 100644
--- a/dpkg-deb/dpkg-deb.h
+++ b/dpkg-deb/dpkg-deb.h
@@ -35,8 +35,21 @@ action_func do_fsystarfile;
extern int opt_verbose;
extern int debugflag, nocheckflag, oldformatflag;
+enum dpkg_tar_options {
+ /** Output the tar file directly, without any processing. */
+ DPKG_TAR_PASSTHROUGH = 0,
+ /** List tar files. */
+ DPKG_TAR_LIST = DPKG_BIT(0),
+ /** Extract tar files. */
+ DPKG_TAR_EXTRACT = DPKG_BIT(1),
+ /** Preserve tar permissions on extract. */
+ DPKG_TAR_PERMS = DPKG_BIT(2),
+ /** Do not set tar mtime on extract. */
+ DPKG_TAR_NOMTIME = DPKG_BIT(3),
+};
+
void extracthalf(const char *debar, const char *dir,
- const char *taroption, int admininfo);
+ enum dpkg_tar_options taroption, int admininfo);
extern const char *showformat;
extern struct compress_params compress_params;
diff --git a/dpkg-deb/extract.c b/dpkg-deb/extract.c
index 42a0e07..7655158 100644
--- a/dpkg-deb/extract.c
+++ b/dpkg-deb/extract.c
@@ -104,8 +104,8 @@ read_line(int fd, char *buf, size_t min_size, size_t
max_size)
}
void
-extracthalf(const char *debar, const char *dir, const char *taroption,
- int admininfo)
+extracthalf(const char *debar, const char *dir,
+ enum dpkg_tar_options taroption, int admininfo)
{
struct dpkg_error err;
const char *errstr;
@@ -302,7 +302,19 @@ extracthalf(const char *debar, const char *dir, const char
*taroption,
command_init(&cmd, TAR, "tar");
command_add_arg(&cmd, "tar");
- command_add_arg(&cmd, taroption);
+ if ((taroption & DPKG_TAR_LIST) && (taroption & DPKG_TAR_EXTRACT))
+ command_add_arg(&cmd, "-xv");
+ else if (taroption & DPKG_TAR_EXTRACT)
+ command_add_arg(&cmd, "-x");
+ else if (taroption & DPKG_TAR_LIST)
+ command_add_arg(&cmd, "-tv");
+ else
+ internerr("unknown or missing tar action '%d'", taroption);
+
+ if (taroption & DPKG_TAR_PERMS)
+ command_add_arg(&cmd, "-p");
+ if (taroption & DPKG_TAR_NOMTIME)
+ command_add_arg(&cmd, "-m");
command_add_arg(&cmd, "-f");
command_add_arg(&cmd, "-");
@@ -349,7 +361,7 @@ extracthalf(const char *debar, const char *dir, const char
*taroption,
}
static int
-controlextractvextract(int admin, const char *taroptions,
+controlextractvextract(int admin, enum dpkg_tar_options taroptions,
const char *const *argv)
{
const char *debar, *dir;
@@ -379,7 +391,7 @@ do_fsystarfile(const char *const *argv)
badusage(_("--%s needs a .deb filename argument"),cipaction->olong);
if (*argv)
badusage(_("--%s takes only one argument (.deb
filename)"),cipaction->olong);
- extracthalf(debar, NULL, NULL, 0);
+ extracthalf(debar, NULL, DPKG_TAR_PASSTHROUGH, 0);
return 0;
}
@@ -387,16 +399,18 @@ do_fsystarfile(const char *const *argv)
int
do_control(const char *const *argv)
{
- return controlextractvextract(1, "x", argv);
+ return controlextractvextract(1, DPKG_TAR_EXTRACT, argv);
}
int
do_extract(const char *const *argv)
{
+ enum dpkg_tar_options options = DPKG_TAR_EXTRACT | DPKG_TAR_PERMS;
+
if (opt_verbose)
- return controlextractvextract(0, "xpv", argv);
- else
- return controlextractvextract(0, "xp", argv);
+ options |= DPKG_TAR_LIST;
+
+ return controlextractvextract(0, options, argv);
}
int
@@ -410,6 +424,7 @@ do_vextract(const char *const *argv)
int
do_raw_extract(const char *const *argv)
{
+ enum dpkg_tar_options data_options;
const char *debar, *dir;
char *control_dir;
@@ -428,11 +443,12 @@ do_raw_extract(const char *const *argv)
m_asprintf(&control_dir, "%s/%s", dir, EXTRACTCONTROLDIR);
+ data_options = DPKG_TAR_EXTRACT | DPKG_TAR_PERMS;
if (opt_verbose)
- extracthalf(debar, dir, "xpv", 0);
- else
- extracthalf(debar, dir, "xp", 0);
- extracthalf(debar, control_dir, "x", 1);
+ data_options |= DPKG_TAR_LIST;
+
+ extracthalf(debar, dir, data_options, 0);
+ extracthalf(debar, control_dir, DPKG_TAR_EXTRACT, 1);
free(control_dir);
diff --git a/dpkg-deb/info.c b/dpkg-deb/info.c
index 1788427..e813f76 100644
--- a/dpkg-deb/info.c
+++ b/dpkg-deb/info.c
@@ -82,7 +82,7 @@ static void info_prepare(const char *const **argvp,
*dirp = dbuf;
push_cleanup(cu_info_prepare, -1, NULL, 0, 1, (void *)dbuf);
- extracthalf(*debarp, dbuf, "mx", admininfo);
+ extracthalf(*debarp, dbuf, DPKG_TAR_EXTRACT | DPKG_TAR_NOMTIME, admininfo);
}
static int ilist_select(const struct dirent *de) {
@@ -331,7 +331,7 @@ do_contents(const char *const *argv)
if (debar == NULL || *argv)
badusage(_("--%s takes exactly one argument"), cipaction->olong);
- extracthalf(debar, NULL, "tv", 0);
+ extracthalf(debar, NULL, DPKG_TAR_LIST, 0);
return 0;
}
--
dpkg's main repository
--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]