Source: dictd
Version: 1.12.1+dfsg-3
Severity: wishlist
Tags: patch
User: reproducible-builds@lists.alioth.debian.org
Usertags: toolchain
X-Debbugs-Cc: reproducible-builds@lists.alioth.debian.org

Hi,

While working on the "reproducible builds" effort [1], we have noticed
that dictzip adds the filename and timestamp to the generated .dz files.

The attached patch adds a --no-name flag (like gzip) that disables this.
This will make it easier and cleaner for maintainers to make their
builds reproducible.

 [1]: https://wiki.debian.org/ReproducibleBuilds


Regards,

-- 
      ,''`.
     : :'  :     Chris Lamb
     `. `'`      la...@debian.org / chris-lamb.co.uk
       `-
diff --git a/data.h b/data.h
index 2fa54f2..ca0f564 100644
--- a/data.h
+++ b/data.h
@@ -33,7 +33,8 @@ extern void dict_data_close (
 extern void     dict_data_print_header( FILE *str, dictData *data );
 extern int      dict_data_zip(
    const char *inFilename, const char *outFilename,
-   const char *preFilter, const char *postFilter );
+   const char *preFilter, const char *postFilter,
+   int nonameFlag );
 
 extern char *dict_data_obtain (
    const dictDatabase *db,
diff --git a/dictzip.1.in b/dictzip.1.in
index 7b2c6e2..5b51173 100644
--- a/dictzip.1.in
+++ b/dictzip.1.in
@@ -172,6 +172,9 @@ license and quit.
 Check the compressed file integrity.  This option is not implemented.
 Instead, it will list the header information.
 .TP
+.BR \-n " or " \-\-no-name
+Don't save the original filename and timestamp.
+.TP
 .BR \-v " or " \-\-verbose
 Verbose. Display extra information during compression.
 .TP
diff --git a/dictzip.c b/dictzip.c
index 3e8000d..f917407 100644
--- a/dictzip.c
+++ b/dictzip.c
@@ -127,7 +127,8 @@ void dict_data_print_header( FILE *str, dictData *header )
 }
 
 int dict_data_zip( const char *inFilename, const char *outFilename,
-                  const char *preFilter, const char *postFilter )
+                  const char *preFilter, const char *postFilter,
+                  int nonameFlag )
 {
    char          inBuffer[IN_BUFFER_SIZE];
    char          outBuffer[OUT_BUFFER_SIZE];
@@ -162,11 +163,16 @@ int dict_data_zip( const char *inFilename, const char 
*outFilename,
       err_fatal_errno( __func__,
                       "Cannot open \"%s\"for write\n", outFilename );
 
-   origFilename = xmalloc( strlen( inFilename ) + 1 );
-   if ((pt = strrchr( inFilename, '/' )))
-      strcpy( origFilename, pt + 1 );
-   else
-      strcpy( origFilename, inFilename );
+   if (nonameFlag) {
+      origFilename = xmalloc( 1 );
+      origFilename[0] = '\0';
+   } else {
+      origFilename = xmalloc( strlen( inFilename ) + 1 );
+      if ((pt = strrchr( inFilename, '/' )))
+         strcpy( origFilename, pt + 1 );
+      else
+         strcpy( origFilename, inFilename );
+   }
 
    /* Initialize compression engine */
    zStream.zalloc    = NULL;
@@ -210,10 +216,12 @@ int dict_data_zip( const char *inFilename, const char 
*outFilename,
 #if HEADER_CRC
    header[GZ_FLG]        |= GZ_FHCRC;
 #endif
-   header[GZ_MTIME+3]    = (st.st_mtime & 0xff000000) >> 24;
-   header[GZ_MTIME+2]    = (st.st_mtime & 0x00ff0000) >> 16;
-   header[GZ_MTIME+1]    = (st.st_mtime & 0x0000ff00) >>  8;
-   header[GZ_MTIME+0]    = (st.st_mtime & 0x000000ff) >>  0;
+   if (!nonameFlag) {
+      header[GZ_MTIME+3]    = (st.st_mtime & 0xff000000) >> 24;
+      header[GZ_MTIME+2]    = (st.st_mtime & 0x00ff0000) >> 16;
+      header[GZ_MTIME+1]    = (st.st_mtime & 0x0000ff00) >>  8;
+      header[GZ_MTIME+0]    = (st.st_mtime & 0x000000ff) >>  0;
+   }
    header[GZ_XFL]        = GZ_MAX;
    header[GZ_OS]         = GZ_OS_UNIX;
    header[GZ_XLEN+1]     = (extraLength & 0xff00) >> 8;
@@ -376,6 +384,7 @@ static void help( void )
       "",
       "-d --decompress      decompress",
       "-f --force           force overwrite of output file",
+      "-n --no-name         don't save the original filename and timestamp",
       "-h --help            give this help",
       "-k --keep            do not delete original file",
       "-l --list            list compressed file contents",
@@ -409,6 +418,7 @@ int main( int argc, char **argv )
    int           listFlag       = 0;
    int           stdoutFlag     = 0;
    int           testFlag       = 0;
+   int           nonameFlag     = 0;
    char          buffer[BUFFERSIZE];
    char          *buf;
    char          *pre           = NULL;
@@ -426,6 +436,7 @@ int main( int argc, char **argv )
       { "stdout",       0, 0, 'c' },
       { "decompress",   0, 0, 'd' },
       { "force",        0, 0, 'f' },
+      { "no-name",      0, 0, 'n' },
       { "help",         0, 0, 'h' },
       { "keep",         0, 0, 'k' },
       { "list",         0, 0, 'l' },
@@ -463,11 +474,12 @@ int main( int argc, char **argv )
 #endif
 
    while ((c = getopt_long( argc, argv,
-                           "cdfhklLe:E:s:S:tvVD:p:P:",
+                           "cdfnhklLe:E:s:S:tvVD:p:P:",
                            longopts, NULL )) != EOF)
       switch (c) {
       case 'd': ++decompressFlag;                                      break;
       case 'f': ++forceFlag;                                           break;
+      case 'n': ++nonameFlag;                                          break;
       case 'k': ++keepFlag;                                            break;
       case 'l': ++listFlag;                                            break;
       case 'L': license(); exit( 1 );                                  break;
@@ -542,7 +554,7 @@ int main( int argc, char **argv )
         }
       } else {
         snprintf( buffer,BUFFERSIZE-1, "%s.dz", argv[i] );
-        if (!dict_data_zip( argv[i], buffer, pre, post )) {
+        if (!dict_data_zip( argv[i], buffer, pre, post, nonameFlag )) {
            if (!keepFlag && unlink( argv[i] ))
                err_fatal_errno( __func__, "Cannot unlink %s\n", argv[i] );
         } else {
_______________________________________________
Reproducible-builds mailing list
Reproducible-builds@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/reproducible-builds

Reply via email to