RPM Community Forums

Mailing List Message of <rpm-devel>

Re: [PATCH] fix RPMTAG_SIZE counter

From: Jeff Johnson <n3npq@mac.com>
Date: Mon 16 Jun 2008 - 07:32:49 CEST
Message-id: <A2164E7F-518D-4C06-8B04-462BB92B2321@mac.com>
Oooh, nice! Thanks for the patch! I'll merge and double
check the patch tomorrow.

(aside) I've known the RPMTAG_SIZE problem(s) for years. You are now
more qualified to hack on rpm than several former and current
rpm maintainers at major linux vendors with whom I'm acquainted.

If you would like write access @rpm5.org cvs, please send along
a pubkey and I'll add you to the team.

73 de Jeff

On Jun 15, 2008, at 11:23 PM, Alexey Tourbin wrote:

> RPMTAG_SIZE counter is broken a bit.
>
> 1) Duplicate file entries are not getting merged.
>
> %install
> mkdir -p %buildroot/foo
> head -c 1024 /dev/zero >%buildroot/foo/1
> %files
> /foo/1
> /foo/1
>
> RPMTAG_SIZE == 2048.
>
> 2) File flags are not getting mreged.
>
> %install
> mkdir -p %buildroot/foo
> head -c 1024 /dev/zero >%buildroot/foo/1
> %files
> /foo/1
> %exclude /foo/1
>
> RPMTAG_SIZE == 1024 (empty package).
>
> 3) Similar problems with %ghost files.
>
> To fix the problem, RPMTAG_SIZE counter should be invoked after
> file dups are merged.  This means the code should be moved from
> addFile() to genCpioListAndHeader().
>
> --- rpm-5.1.3/build/files.c-	2008-04-06 12:47:47 +0400
> +++ rpm-5.1.3/build/files.c	2008-06-16 07:16:45 +0400
> @@ -1601,15 +1601,6 @@ if (!(_rpmbuildFlags & 4))
>  /*@=moduncon =noeffectuncon @*/
>      sxfn = _free(sxfn);
>
> -    ui32 = fl->totalFileSize;
> -    he->tag = RPMTAG_SIZE;
> -    he->t = RPM_UINT32_TYPE;
> -    he->p.ui32p = &ui32;
> -    he->c = 1;
> -    he->append = 1;
> -    xx = headerPut(h, he, 0);
> -    he->append = 0;
> -
>  if (_rpmbuildFlags & 4) {
>  (void) rpmlibNeedsFeature(h, "PayloadFilesHavePrefix", "4.0-1");
>  (void) rpmlibNeedsFeature(h, "CompressedFileNames", "3.0.4-1");
> @@ -1713,7 +1704,44 @@ if (_rpmbuildFlags & 4) {
>  	if (isSrc)
>  	    fi->fmapflags[i] |= IOSM_FOLLOW_SYMLINKS;
>
> +	if (S_ISREG(flp->fl_mode) && flp->fl_nlink == 1)
> +	    fl->totalFileSize += flp->fl_size;
> +	else if (S_ISREG(flp->fl_mode) && flp->fl_nlink > 1) {
> +	    /* Hard links need be counted only once. */
> +	    FileListRec jlp;
> +	    int j;
> +	    int found = 0;
> +	    for (j = i+1, jlp = flp+1; (unsigned)j < fi->fc; j++, jlp++) {
> +		while (((jlp - fl->fileList) < (fl->fileListRecsUsed - 1)) &&
> +			!strcmp(jlp->fileURL, jlp[1].fileURL))
> +		    jlp++;
> +		if (!S_ISREG(jlp->fl_mode))
> +		    continue;
> +		if (flp->fl_nlink != jlp->fl_nlink)
> +		    continue;
> +		if (flp->fl_ino != jlp->fl_ino)
> +		    continue;
> +		if (flp->fl_dev != jlp->fl_dev)
> +		    continue;
> +		if (jlp->flags & (RPMFILE_EXCLUDE | RPMFILE_GHOST))
> +		    continue;
> +		found = 1;
> +		break;
> +	    }
> +	    if (!found) /* last entry in hardlink set */
> +		fl->totalFileSize += flp->fl_size;
> +	}
>      }
> +
> +    ui32 = fl->totalFileSize;
> +    he->tag = RPMTAG_SIZE;
> +    he->t = RPM_UINT32_TYPE;
> +    he->p.ui32p = &ui32;
> +    he->c = 1;
> +    he->append = 1;
> +    xx = headerPut(h, he, 0);
> +    he->append = 0;
> +
>      /*@-compdef@*/
>      if (fip)
>  	*fip = fi;
> @@ -1947,26 +1975,6 @@ static int addFile(FileList fl, const ch
>  	flp->specdFlags = fl->currentSpecdFlags;
>  	flp->verifyFlags = fl->currentVerifyFlags;
>
> -	/* Hard links need be counted only once. */
> -	if (S_ISREG(flp->fl_mode) && flp->fl_nlink > 1) {
> -	    FileListRec ilp;
> -	    for (i = 0;  i < fl->fileListRecsUsed; i++) {
> -		ilp = fl->fileList + i;
> -		if (!S_ISREG(ilp->fl_mode))
> -		    continue;
> -		if (flp->fl_nlink != ilp->fl_nlink)
> -		    continue;
> -		if (flp->fl_ino != ilp->fl_ino)
> -		    continue;
> -		if (flp->fl_dev != ilp->fl_dev)
> -		    continue;
> -		break;
> -	    }
> -	} else
> -	    i = fl->fileListRecsUsed;
> -
> -	if (!(flp->flags & RPMFILE_EXCLUDE) && S_ISREG(flp->fl_mode) && i  
> >= fl->fileListRecsUsed)
> -	    fl->totalFileSize += flp->fl_size;
>      }
>
>      fl->fileListRecsUsed++;
> @@ -2758,8 +2766,6 @@ int processSourceFiles(Spec spec)
>  #endif
>  	flp->langs = xstrdup("");
>  	
> -	fl.totalFileSize += flp->fl_size;
> -	
>  	if (! (flp->uname && flp->gname)) {
>  	    rpmlog(RPMLOG_ERR, _("Bad owner/group: %s\n"), diskURL);
>  	    rc = fl.processingFailed = 1;
Received on Mon Jun 16 07:34:14 2008
Driven by Jeff Johnson and the RPM project team.
Hosted by OpenPKG and Ralf S. Engelschall.
Powered by FreeBSD and OpenPKG.