Просмотр исходного кода

Normalize ar member names when reading

This removes all trailing spaces and the optional trailing slash on
GNU-style ar format, making it easier to parse and avoiding having to
compare against the compat strings.
Guillem Jover лет назад: 16
Родитель
Сommit
e5c584abd3
6 измененных файлов с 33 добавлено и 27 удалено
  1. 2 0
      debian/changelog
  2. 6 11
      dpkg-deb/dpkg-deb.h
  3. 14 13
      dpkg-deb/extract.c
  4. 1 1
      dpkg-split/dpkg-split.h
  5. 8 1
      dpkg-split/info.c
  6. 2 1
      man/deb-split.5

+ 2 - 0
debian/changelog

@@ -54,6 +54,8 @@ dpkg (1.15.6) UNRELEASED; urgency=low
     are already fatal on that case.
     are already fatal on that case.
   * Add new deb-split(5) man page.
   * Add new deb-split(5) man page.
   * Fix misspellings of “explicitly” all over the place.
   * Fix misspellings of “explicitly” all over the place.
+  * Normalize ar member names when reading (removing trailing spaces and
+    slash), this allows deb-split packages be created with GNU ar.
 
 
   [ Modestas Vainius ]
   [ Modestas Vainius ]
   * Implement symbol patterns (Closes: #563752). From now on, it is possible to
   * Implement symbol patterns (Closes: #563752). From now on, it is possible to

+ 6 - 11
dpkg-deb/dpkg-deb.h

@@ -52,17 +52,12 @@ extern enum compress_type compress_type;
 #define OLDDEBDIR		"DEBIAN"
 #define OLDDEBDIR		"DEBIAN"
 #define OLDOLDDEBDIR		".DEBIAN"
 #define OLDOLDDEBDIR		".DEBIAN"
 
 
-#define DEBMAGIC		"debian-binary   "
-#define ADMINMEMBER		"control.tar.gz  "
-#define ADMINMEMBER_COMPAT	"control.tar.gz/ "
-#define DATAMEMBER_GZ		"data.tar.gz     "
-#define DATAMEMBER_COMPAT_GZ	"data.tar.gz/    "
-#define DATAMEMBER_BZ2   	"data.tar.bz2    "
-#define DATAMEMBER_COMPAT_BZ2  	"data.tar.bz2/   "
-#define DATAMEMBER_LZMA		"data.tar.lzma   "
-#define DATAMEMBER_COMPAT_LZMA	"data.tar.lzma/  "
-#define DATAMEMBER_CAT   	"data.tar        "
-#define DATAMEMBER_COMPAT_CAT  	"data.tar/       "
+#define DEBMAGIC		"debian-binary"
+#define ADMINMEMBER		"control.tar.gz"
+#define DATAMEMBER_GZ		"data.tar.gz"
+#define DATAMEMBER_BZ2		"data.tar.bz2"
+#define DATAMEMBER_LZMA		"data.tar.lzma"
+#define DATAMEMBER_CAT		"data.tar"
 
 
 #define MAXFILENAME 2048
 #define MAXFILENAME 2048
 #define MAXFIELDNAME 200
 #define MAXFIELDNAME 200

+ 14 - 13
dpkg-deb/extract.c

@@ -41,6 +41,7 @@
 #include <dpkg/buffer.h>
 #include <dpkg/buffer.h>
 #include <dpkg/subproc.h>
 #include <dpkg/subproc.h>
 #include <dpkg/compress.h>
 #include <dpkg/compress.h>
+#include <dpkg/ar.h>
 #include <dpkg/myopt.h>
 #include <dpkg/myopt.h>
 
 
 #include "dpkg-deb.h"
 #include "dpkg-deb.h"
@@ -137,13 +138,15 @@ void extracthalf(const char *debar, const char *directory,
     for (;;) {
     for (;;) {
       if (fread(&arh,1,sizeof(arh),ar) != sizeof(arh))
       if (fread(&arh,1,sizeof(arh),ar) != sizeof(arh))
         readfail(ar,debar,_("between members"));
         readfail(ar,debar,_("between members"));
+
+      dpkg_ar_normalize_name(&arh);
+
       if (memcmp(arh.ar_fmag,ARFMAG,sizeof(arh.ar_fmag)))
       if (memcmp(arh.ar_fmag,ARFMAG,sizeof(arh.ar_fmag)))
         ohshit(_("file `%.250s' is corrupt - bad magic at end of first header"),debar);
         ohshit(_("file `%.250s' is corrupt - bad magic at end of first header"),debar);
       memberlen= parseheaderlength(arh.ar_size,sizeof(arh.ar_size),
       memberlen= parseheaderlength(arh.ar_size,sizeof(arh.ar_size),
                                    debar, _("member length"));
                                    debar, _("member length"));
       if (!header_done) {
       if (!header_done) {
-        if (memcmp(arh.ar_name, DEBMAGIC, sizeof(arh.ar_name)) &&
-	    memcmp(arh.ar_name,"debian-binary/   ",sizeof(arh.ar_name)))
+        if (strncmp(arh.ar_name, DEBMAGIC, sizeof(arh.ar_name)) != 0)
           ohshit(_("file `%.250s' is not a debian binary archive (try dpkg-split?)"),debar);
           ohshit(_("file `%.250s' is not a debian binary archive (try dpkg-split?)"),debar);
         infobuf= m_malloc(memberlen+1);
         infobuf= m_malloc(memberlen+1);
         if (fread(infobuf,1, memberlen + (memberlen&1), ar) != memberlen + (memberlen&1))
         if (fread(infobuf,1, memberlen + (memberlen&1), ar) != memberlen + (memberlen&1))
@@ -167,24 +170,22 @@ void extracthalf(const char *debar, const char *directory,
            */
            */
 	stream_null_copy(ar, memberlen + (memberlen&1),_("skipped member data from %s"), debar);
 	stream_null_copy(ar, memberlen + (memberlen&1),_("skipped member data from %s"), debar);
       } else {
       } else {
-        adminmember=
-          (!memcmp(arh.ar_name,ADMINMEMBER,sizeof(arh.ar_name)) ||
-	  !memcmp(arh.ar_name,ADMINMEMBER_COMPAT,sizeof(arh.ar_name))) ? 1 : -1;
+	if (strncmp(arh.ar_name, ADMINMEMBER, sizeof(arh.ar_name)) == 0)
+	  adminmember = 1;
+	else
+	  adminmember = -1;
+
 	if (adminmember == -1) {
 	if (adminmember == -1) {
-	  if (!memcmp(arh.ar_name,DATAMEMBER_GZ,sizeof(arh.ar_name)) ||
-	      !memcmp(arh.ar_name,DATAMEMBER_COMPAT_GZ,sizeof(arh.ar_name))) {
+	  if (strncmp(arh.ar_name, DATAMEMBER_GZ, sizeof(arh.ar_name)) == 0) {
 	    adminmember= 0;
 	    adminmember= 0;
 	    compress_type = compress_type_gzip;
 	    compress_type = compress_type_gzip;
-	  } else if (!memcmp(arh.ar_name,DATAMEMBER_BZ2,sizeof(arh.ar_name)) ||
-		     !memcmp(arh.ar_name,DATAMEMBER_COMPAT_BZ2,sizeof(arh.ar_name))) {
+	  } else if (strncmp(arh.ar_name, DATAMEMBER_BZ2, sizeof(arh.ar_name)) == 0) {
 	    adminmember= 0;
 	    adminmember= 0;
 	    compress_type = compress_type_bzip2;
 	    compress_type = compress_type_bzip2;
-	  } else if (!memcmp(arh.ar_name, DATAMEMBER_LZMA, sizeof(arh.ar_name)) ||
-		     !memcmp(arh.ar_name, DATAMEMBER_COMPAT_LZMA, sizeof(arh.ar_name))) {
+	  } else if (strncmp(arh.ar_name, DATAMEMBER_LZMA, sizeof(arh.ar_name)) == 0) {
 	    adminmember = 0;
 	    adminmember = 0;
 	    compress_type = compress_type_lzma;
 	    compress_type = compress_type_lzma;
-	  } else if (!memcmp(arh.ar_name,DATAMEMBER_CAT,sizeof(arh.ar_name)) ||
-		     !memcmp(arh.ar_name,DATAMEMBER_COMPAT_CAT,sizeof(arh.ar_name))) {
+	  } else if (strncmp(arh.ar_name, DATAMEMBER_CAT, sizeof(arh.ar_name)) == 0) {
 	    adminmember= 0;
 	    adminmember= 0;
 	    compress_type = compress_type_cat;
 	    compress_type = compress_type_cat;
 	  } else {
 	  } else {

+ 1 - 1
dpkg-split/dpkg-split.h

@@ -70,7 +70,7 @@ void addtopartlist(struct partinfo**, struct partinfo*, struct partinfo *refi);
 
 
 #define PARTSDIR          "parts/"
 #define PARTSDIR          "parts/"
 
 
-#define PARTMAGIC         "debian-split    "
+#define PARTMAGIC         "debian-split"
 #define HEADERALLOWANCE    1024
 #define HEADERALLOWANCE    1024
 
 
 #define SPLITPARTDEFMAX    (450 * 1024)
 #define SPLITPARTDEFMAX    (450 * 1024)

+ 8 - 1
dpkg-split/info.c

@@ -35,6 +35,7 @@
 #include <dpkg/i18n.h>
 #include <dpkg/i18n.h>
 #include <dpkg/dpkg.h>
 #include <dpkg/dpkg.h>
 #include <dpkg/dpkg-db.h>
 #include <dpkg/dpkg-db.h>
+#include <dpkg/ar.h>
 #include <dpkg/myopt.h>
 #include <dpkg/myopt.h>
 
 
 #include "dpkg-split.h"
 #include "dpkg-split.h"
@@ -95,7 +96,10 @@ struct partinfo *read_info(FILE *partfile, const char *fn, struct partinfo *ir)
     return NULL;
     return NULL;
   
   
   if (fread(&arh,1,sizeof(arh),partfile) != sizeof(arh)) rerreof(partfile,fn);
   if (fread(&arh,1,sizeof(arh),partfile) != sizeof(arh)) rerreof(partfile,fn);
-  if (memcmp(arh.ar_name, PARTMAGIC, sizeof(arh.ar_name)))
+
+  dpkg_ar_normalize_name(&arh);
+
+  if (strncmp(arh.ar_name, PARTMAGIC, sizeof(arh.ar_name)) != 0)
     return NULL;
     return NULL;
   if (memcmp(arh.ar_fmag,ARFMAG,sizeof(arh.ar_fmag)))
   if (memcmp(arh.ar_fmag,ARFMAG,sizeof(arh.ar_fmag)))
     ohshit(_("file `%.250s' is corrupt - bad magic at end of first header"),fn);
     ohshit(_("file `%.250s' is corrupt - bad magic at end of first header"),fn);
@@ -150,6 +154,9 @@ struct partinfo *read_info(FILE *partfile, const char *fn, struct partinfo *ir)
   ir->thispartn= templong;
   ir->thispartn= templong;
 
 
   if (fread(&arh,1,sizeof(arh),partfile) != sizeof(arh)) rerreof(partfile,fn);
   if (fread(&arh,1,sizeof(arh),partfile) != sizeof(arh)) rerreof(partfile,fn);
+
+  dpkg_ar_normalize_name(&arh);
+
   if (memcmp(arh.ar_fmag,ARFMAG,sizeof(arh.ar_fmag)))
   if (memcmp(arh.ar_fmag,ARFMAG,sizeof(arh.ar_fmag)))
     ohshit(_("file `%.250s' is corrupt - bad magic at end of second header"),fn);
     ohshit(_("file `%.250s' is corrupt - bad magic at end of second header"),fn);
   if (strncmp(arh.ar_name,"data",4))
   if (strncmp(arh.ar_name,"data",4))

+ 2 - 1
man/deb-split.5

@@ -1,4 +1,4 @@
-.TH deb\-split 5 "2009-12-31" "Debian Project" "Debian"
+.TH deb\-split 5 "2010-01-28" "Debian Project" "Debian"
 .SH NAME
 .SH NAME
 deb\-split \- Debian multi-part binary package format
 deb\-split \- Debian multi-part binary package format
 .SH SYNOPSIS
 .SH SYNOPSIS
@@ -8,6 +8,7 @@ The multi-part \fB.deb\fP format is used to split big packages into smaller
 pieces to ease transport in small media.
 pieces to ease transport in small media.
 .SH FORMAT
 .SH FORMAT
 The file is an \fBar\fP archive with a magic value of \fB!<arch>\fP.
 The file is an \fBar\fP archive with a magic value of \fB!<arch>\fP.
+The file names might contain a trailing slash (since dpkg 1.15.6).
 .PP
 .PP
 The first member is named \fBdebian\-split\fP and contains a series
 The first member is named \fBdebian\-split\fP and contains a series
 of lines, separated by newlines. Currently seven lines are present.
 of lines, separated by newlines. Currently seven lines are present.