Subject: Re: bin/24477 (install(1) metalog: fix digest of /dev/null, and add size field)
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org, apb@cequrux.com>
From: Daniel de Kok <danieldk@pobox.com>
List: netbsd-bugs
Date: 09/26/2006 04:25:01
The following reply was made to PR bin/24477; it has been noted by GNATS.

From: Daniel de Kok <danieldk@pobox.com>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: bin/24477 (install(1) metalog: fix digest of /dev/null, and add size field)
Date: Tue, 26 Sep 2006 06:22:21 +0200

 --C7zPtVaVf+AK4Oqc
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 (Let's try this once more, sorry if this e-mail appears more than once.)
 
 I a agree that having hash for /dev/zero-created files is more consistent.
 But hardcoding the null hashes adds redundancy. How about the attached
 patch?
 
 I don't really have an opinion about adding file sizes. Since that is
 a separate feature request, maybe it's good to discuss that on
 tech-userlevel first?
 
 -- Daniel
 
 --C7zPtVaVf+AK4Oqc
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename="xinstall-nulldigest.diff"
 
 Index: xinstall.c
 ===================================================================
 RCS file: /cvsroot/src/usr.bin/xinstall/xinstall.c,v
 retrieving revision 1.97
 diff -b -u -r1.97 xinstall.c
 --- xinstall.c	25 Sep 2006 13:21:19 -0000	1.97
 +++ xinstall.c	25 Sep 2006 14:06:42 -0000
 @@ -102,6 +102,7 @@
  	DIGEST_SHA1,
  } digesttype = DIGEST_NONE;
  char	*digest;
 +char	*nulldigest;	/* The digest of an empty file. */
  
  #define LN_ABSOLUTE	0x01
  #define LN_RELATIVE	0x02
 @@ -282,12 +283,16 @@
  		if (0) {
  		} else if (strcmp(digest, "none") == 0) {
  			digesttype = DIGEST_NONE;
 +			nulldigest = NULL;
  		} else if (strcmp(digest, "md5") == 0) {
  			digesttype = DIGEST_MD5;
 +			nulldigest = MD5Data(NULL, 0, NULL);
  		} else if (strcmp(digest, "rmd160") == 0) {
  			digesttype = DIGEST_RMD160;
 +			nulldigest = RMD160Data(NULL, 0, NULL);
  		} else if (strcmp(digest, "sha1") == 0) {
  			digesttype = DIGEST_SHA1;
 +			nulldigest = SHA1Data(NULL, 0, NULL);
  		} else {
  			warnx("unknown digest `%s'", digest);
  			usage();
 @@ -366,6 +371,7 @@
  			(void)unlink(to_name);
  	}
  	install(*argv, to_name, iflags);
 +	free(nulldigest);
  	exit(0);
  }
  
 @@ -740,7 +746,8 @@
  	}
  #endif
  
 -	metadata_log(to_name, "file", tv, NULL, digestresult);
 +	metadata_log(to_name, "file", tv, NULL,
 +		(devnull ? nulldigest : digestresult));
  	free(digestresult);
  }
  
 
 --C7zPtVaVf+AK4Oqc--