On Tue, 2014-02-18 at 13:01:48 +0100, Guillem Jover wrote: > Package: udpkg > Version: 1.16 > Severity: wishlist > Tags: patch > X-Debbugs-CC: Philipp Kern <[email protected]>
> Here's a patch series adding data.tar, control.tar and control.tar.xz > support, the uncompressed member support just out of completeness. To > create a deb package with a different control.tar compression you can > use «dpkg-deb --uniform-compression pkg/» for example. > > Note I've only tested «udpkg -c» and «udpkg -f», the changes in unpacking > are pretty obvious, but testing them would be nice. I've also used cat > for the uncompressed members as I didn't think further optimization there > was worth it(?). I've also tried to use the prevailing coding-style, > which in some cases conflicted with the immediate surrounding code. And then forgot to attach the patches… Thanks, Guillem
From b806fc9a73e79b561fad9e40e34d44d86031e4a1 Mon Sep 17 00:00:00 2001 From: Guillem Jover <[email protected]> Date: Sun, 16 Feb 2014 02:25:10 +0100 Subject: [PATCH 1/4] Pass member_base as an argument to get_compression_type() Allow other member base names, instead of hardcoding data.tar. --- udpkg.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/udpkg.c b/udpkg.c index 2adfd16..73fa9d8 100644 --- a/udpkg.c +++ b/udpkg.c @@ -163,7 +163,9 @@ static const char *decompression_tool (const compression_type t) { } } -static compression_type get_compression_type (struct package_t *pkg) { +static compression_type get_compression_type(struct package_t *pkg, + const char *member_base) +{ FILE *infp = NULL; char buf[1024]; char *extension = NULL; @@ -177,8 +179,8 @@ static compression_type get_compression_type (struct package_t *pkg) { } while (fgets(buf, sizeof(buf), infp)) { - if (strncmp(buf, data_member_base, strlen(data_member_base)) == 0) { - extension = buf + strlen(data_member_base); + if (strncmp(buf, member_base, strlen(member_base)) == 0) { + extension = buf + strlen(member_base); if (extension[strlen(extension) - 1] == '\n') extension[strlen(extension) - 1] = '\0'; break; @@ -188,7 +190,7 @@ static compression_type get_compression_type (struct package_t *pkg) { if (extension == NULL) { FPRINTF(stderr, "No %s* found in %s\n", - data_member_base, pkg->file); + member_base, pkg->file); return unknown_compression; } @@ -200,7 +202,7 @@ static compression_type get_compression_type (struct package_t *pkg) { } else { FPRINTF(stderr, "Invalid compression type for %s* of %s\n", - data_member_base, pkg->file); + member_base, pkg->file); return unknown_compression; } } @@ -226,7 +228,7 @@ static int dpkg_dounpack(struct package_t *pkg) DPRINTF("Unpacking %s\n", pkg->package); - compression_type = get_compression_type(pkg); + compression_type = get_compression_type(pkg, data_member_base); if (compression_type == unknown_compression) return 1; @@ -556,7 +558,7 @@ static int dpkg_contents(struct package_t *pkg) reqarg(pkg); - compression_type = get_compression_type(pkg); + compression_type = get_compression_type(pkg, data_member_base); if (compression_type == unknown_compression) return 1; -- 1.9.0.rc3.244.g3497008
From 193c1b896291da42844953bdf693245ec4c8adaa Mon Sep 17 00:00:00 2001 From: Guillem Jover <[email protected]> Date: Sun, 16 Feb 2014 02:28:34 +0100 Subject: [PATCH 2/4] Add support for uncompressed deb members --- udpkg.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/udpkg.c b/udpkg.c index 73fa9d8..ef6bdf7 100644 --- a/udpkg.c +++ b/udpkg.c @@ -18,7 +18,7 @@ static int force_configure = 0; static int loadtemplate = 1; -static const char *data_member_base = "data.tar."; +static const char *data_member_base = "data.tar"; /* * Main udpkg implementation routines @@ -144,21 +144,24 @@ typedef enum compression_type compression_type; enum compression_type { gz_compression, xz_compression, + no_compression, unknown_compression, }; static const char *compression_extension (const compression_type t) { switch (t) { - case gz_compression: return "gz"; - case xz_compression: return "xz"; + case gz_compression: return ".gz"; + case xz_compression: return ".xz"; + case no_compression: return ""; default: return ""; } } static const char *decompression_tool (const compression_type t) { switch (t) { - case gz_compression: return "gunzip"; - case xz_compression: return "unxz"; + case gz_compression: return "gunzip -c"; + case xz_compression: return "unxz -c"; + case no_compression: return "cat"; default: return ""; } } @@ -200,6 +203,10 @@ static compression_type get_compression_type(struct package_t *pkg, else if (strcmp(extension, compression_extension(xz_compression)) == 0) { return xz_compression; } + else if (strcmp(extension, compression_extension(no_compression)) == 0) + { + return no_compression; + } else { FPRINTF(stderr, "Invalid compression type for %s* of %s\n", member_base, pkg->file); @@ -239,7 +246,7 @@ static int dpkg_dounpack(struct package_t *pkg) return 1; } - snprintf(buf, sizeof(buf), "ar -p %s %s%s|%s -c|tar -x", + snprintf(buf, sizeof(buf), "ar -p %s %s%s|%s|tar -x", pkg->file, data_member_base, compression_extension(compression_type), decompression_tool(compression_type)); @@ -305,7 +312,7 @@ static int dpkg_dounpack(struct package_t *pkg) * so oddly... */ snprintf(buf, sizeof(buf), - "ar -p %s %s%s|%s -c|tar -t", + "ar -p %s %s%s|%s|tar -t", pkg->file, data_member_base, compression_extension(compression_type), decompression_tool(compression_type)); -- 1.9.0.rc3.244.g3497008
From 2908ab0a20d5a1153325af3a81949674a3efdc32 Mon Sep 17 00:00:00 2001 From: Guillem Jover <[email protected]> Date: Sun, 16 Feb 2014 02:35:44 +0100 Subject: [PATCH 3/4] Add support for control.tar and control.tar.xz --- udpkg.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/udpkg.c b/udpkg.c index ef6bdf7..1715222 100644 --- a/udpkg.c +++ b/udpkg.c @@ -19,6 +19,7 @@ static int force_configure = 0; static int loadtemplate = 1; static const char *data_member_base = "data.tar"; +static const char *control_member_base = "control.tar"; /* * Main udpkg implementation routines @@ -382,6 +383,7 @@ static int dpkg_unpackcontrol(struct package_t *pkg) char *p; char buf[1024], buf2[1024]; FILE *f; + compression_type compression_type; p = strrchr(pkg->file, '/'); if (p) p++; else p = pkg->file; @@ -390,6 +392,10 @@ static int dpkg_unpackcontrol(struct package_t *pkg) *p = 0; p = pkg->package; + compression_type = get_compression_type(pkg, control_member_base); + if (compression_type == unknown_compression) + return 1; + cwd = getcwd(0, 0); snprintf(buf, sizeof(buf), "%s%s", DPKGCIDIR, pkg->package); DPRINTF("dir = %s\n", buf); @@ -403,8 +409,10 @@ static int dpkg_unpackcontrol(struct package_t *pkg) FPRINTF(stderr, "chdir %s: %s\n", buf, strerror(errno)); return 1; } - snprintf(buf, sizeof(buf), "ar -p %s control.tar.gz|tar -xzf -", - pkg->file); + snprintf(buf, sizeof(buf), "ar -p %s %s%s|%s|tar -xf -", + pkg->file, control_member_base, + compression_extension(compression_type), + decompression_tool(compression_type)); if ((r = di_exec_shell_log(buf)) != 0) { FPRINTF(stderr, "%s exited with status %d\n", buf, r); @@ -548,10 +556,18 @@ static int dpkg_fields(struct package_t *pkg) { char *command; int ret; + compression_type compression_type; reqarg(pkg); - command = xasprintf("ar -p %s control.tar.gz|tar -xzOf - ./control", pkg->file); + compression_type = get_compression_type(pkg, control_member_base); + if (compression_type == unknown_compression) + return 1; + + command = xasprintf("ar -p %s %s%s|%s|tar -xOf - ./control", + pkg->file, control_member_base, + compression_extension(compression_type), + decompression_tool(compression_type)); ret = system(command); free(command); return ret; -- 1.9.0.rc3.244.g3497008
From c9b009dd7fc451098dda30f18b016650608a0dca Mon Sep 17 00:00:00 2001 From: Guillem Jover <[email protected]> Date: Sun, 16 Feb 2014 07:32:03 +0100 Subject: [PATCH 4/4] Update .gitignore --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.gitignore b/.gitignore index 9cdaca8..5d8f629 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,14 @@ +*.o autom4te.cache build-stamp config.log config.h +config.h.in config.cache +config.guess config.status +config.sub +configure makefile udpkg -- 1.9.0.rc3.244.g3497008

