]> git.pld-linux.org Git - packages/rpm.git/blob - rpm-payload-use-hashed-inode.patch
- make sure that the output buffer gets truncated after use, otherwise
[packages/rpm.git] / rpm-payload-use-hashed-inode.patch
1 diff -ur rpm-5.4.10/build/files.c rpm-5.4.10-collision/build/files.c
2 --- rpm-5.4.10/build/files.c    2013-03-17 13:17:38.233358389 +0100
3 +++ rpm-5.4.10-collision/build/files.c  2013-03-17 13:07:37.468483625 +0100
4 @@ -1323,6 +1323,26 @@
5      return dalgo;
6  }
7  
8 +static int isHardLink(FileListRec flp, FileListRec tlp)
9 +{
10 +    return ((S_ISREG(flp->fl_mode) && S_ISREG(tlp->fl_mode)) &&
11 +            ((flp->fl_nlink > 1) && (flp->fl_nlink == tlp->fl_nlink)) &&
12 +            (flp->fl_ino == tlp->fl_ino) &&
13 +            (flp->fl_dev == tlp->fl_dev));
14 +}
15 +
16 +static int seenHardLink(FileList fl, FileListRec flp, ino_t *fileid)
17 +{
18 +    FileListRec ilp;
19 +    for (ilp = fl->fileList; ilp < flp; ilp++) {
20 +        if (isHardLink(flp, ilp)) {
21 +            *fileid = ilp - fl->fileList;
22 +            return 1;
23 +        }
24 +    }
25 +    return 0;
26 +}
27 +
28  /**
29   * Add file entries to header.
30   * @todo Should directories have %doc/%config attributes? (#14531)
31 @@ -1370,6 +1390,7 @@
32  
33      for (i = 0, flp = fl->fileList; i < fl->fileListRecsUsed; i++, flp++) {
34         const char *s;
35 +       ino_t fileid = flp - fl->fileList;
36  
37         /* Merge duplicate entries. */
38         while (i < (fl->fileListRecsUsed - 1) &&
39 @@ -1437,6 +1458,13 @@
40         /* Leave room for both dirname and basename NUL's */
41         dpathlen += (strlen(flp->diskURL) + 2);
42  
43 +       /* Excludes and dupes have been filtered out by now. */
44 +       if (S_ISREG(flp->fl_mode)) {
45 +           if (flp->fl_nlink == 1 || !seenHardLink(fl, flp, &fileid)) {
46 +               fl->totalFileSize += flp->fl_size;
47 +           }
48 +       }
49 +
50         /*
51          * Make the header, the OLDFILENAMES will get converted to a 
52          * compressed file list write before we write the actual package to
53 @@ -1519,7 +1547,11 @@
54  
55         /* XXX Hash instead of 64b->32b truncate to prevent aliasing. */
56         {   ino_t _ino = flp->fl_ino;
57 -           ui32 = hashFunctionString(0, &_ino, sizeof(_ino));
58 +       /* don't use hash here, as hash collisions which happen on large packages
59 +          cause bus errors in rpmbuild
60 +           ui32 = hashFunctionString(0, &_ino, sizeof(_ino));
61 +       */
62 +           ui32 = fileid + 1;
63         }
64         he->tag = RPMTAG_FILEINODES;
65         he->t = RPM_UINT32_TYPE;
66 @@ -1752,39 +1780,6 @@
67                 IOSM_MAP_TYPE | IOSM_MAP_MODE | IOSM_MAP_UID | IOSM_MAP_GID;
68         if (isSrc)
69             fi->fmapflags[i] |= IOSM_FOLLOW_SYMLINKS;
70 -
71 -       if (S_ISREG(flp->fl_mode)) {
72 -           int bingo = 1;
73 -           /* Hard links need be tallied only once. */
74 -           if (flp->fl_nlink > 1) {
75 -               FileListRec jlp = flp + 1;
76 -               int j = i + 1;
77 -               for (; (unsigned)j < fi->fc; j++, jlp++) {
78 -                   /* follow outer loop logic */
79 -                   while (((jlp - fl->fileList) < (fl->fileListRecsUsed - 1)) &&
80 -                           !strcmp(jlp->fileURL, jlp[1].fileURL))
81 -                       jlp++;
82 -                   if (jlp->flags & RPMFILE_EXCLUDE) {
83 -                       j--;
84 -                       /*@innercontinue@*/ continue;
85 -                   }
86 -                   if (jlp->flags & RPMFILE_GHOST)
87 -                       /*@innercontinue@*/ continue;
88 -                   if (!S_ISREG(jlp->fl_mode))
89 -                       /*@innercontinue@*/ continue;
90 -                   if (flp->fl_nlink != jlp->fl_nlink)
91 -                       /*@innercontinue@*/ continue;
92 -                   if (flp->fl_ino != jlp->fl_ino)
93 -                       /*@innercontinue@*/ continue;
94 -                   if (flp->fl_dev != jlp->fl_dev)
95 -                       /*@innercontinue@*/ continue;
96 -                   bingo = 0;  /* don't tally hardlink yet. */
97 -                   /*@innerbreak@*/ break;
98 -               }
99 -           }
100 -           if (bingo)
101 -               fl->totalFileSize += flp->fl_size;
102 -       }
103      }
104  
105      ui32 = fl->totalFileSize;
106 --- rpm-5.4.10/lib/fsm.c~
107 +++ rpm-5.4.10/lib/fsm.c
108 @@ -898,6 +898,7 @@ int fsmMapAttrs(IOSM_t fsm)
109  
110      if (fi && i >= 0 && i < (int) fi->fc) {
111         mode_t perms = (S_ISDIR(st->st_mode) ? fi->dperms : fi->fperms);
112 +       ino_t finalInode = (fi->finodes ? (ino_t)fi->finodes[i] : 0);
113         mode_t finalMode = (fi->fmodes ? (mode_t)fi->fmodes[i] : perms);
114         dev_t finalRdev = (dev_t)(fi->frdevs ? fi->frdevs[i] : 0);
115         rpmuint32_t finalMtime = (fi->fmtimes ? fi->fmtimes[i] : 0);
116 @@ -937,6 +938,7 @@ int fsmMapAttrs(IOSM_t fsm)
117             if ((S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode))
118             && st->st_nlink == 0)
119                 st->st_nlink = 1;
120 +           st->st_ino = finalInode;
121             st->st_rdev = finalRdev;
122             st->st_mtime = finalMtime;
123         }
This page took 0.056907 seconds and 3 git commands to generate.