apt-0.5.15lorg2-alt-genpkglist-reqfiles.patch

genpkglist strips file lists by default (without --bloat option).
It keeps only some "useful files" by using a few ad hoc patterns.

This can break file-level dependencies.  Consider pkgA requires
/usr/lib/foo1/bar, and pkgB owns this file without explicitly
providing it.  Now if genpkglist strips /usr/lib/foo1/bar
from pkgB file list, this is going to be an unmet dependency.

This patch changes genpkglist behaviour, so that, when genpkglist
is invoked without --bloat option, it first finds all file-level
dependencies (something like "rpm -qaR |grep ^/").  This requires
a separate pass.  The list of file-level dependencies is saved into
"reqfiles" global variable.  And on the second (normal) pass, the
function usefulFile() is modified to check the "reqfiles" variable;
that is, it should keep a file in the file list if it's been required
by some package in the repo.

(Unfortunately, this patch does not solve all of the problems
I want it to solve; we have separate repos for i586 and noarch --
inter-repo file-level dependencies cannot be resolved this way.)
This commit is contained in:
Alexey Tourbin 2007-08-11 20:01:05 +04:00
parent fe9628abf2
commit 30e27b0f1c
2 changed files with 108 additions and 4 deletions

View File

@ -0,0 +1,106 @@
--- apt-0.5.15lorg2/tools/genpkglist.cc- 2007-08-11 15:10:54 +0400
+++ apt-0.5.15lorg2/tools/genpkglist.cc 2007-08-11 19:36:03 +0400
@@ -18,6 +18,8 @@
#include <map>
#include <iostream>
+#include <tr1/unordered_set>
+
#include <apt-pkg/error.h>
#include <apt-pkg/tagfile.h>
#include <apt-pkg/configuration.h>
@@ -77,20 +79,30 @@ typedef struct {
string url;
} UpdateInfo;
+static std::tr1::unordered_set<std::string> reqfiles;
-static inline int usefullFile(char *a)
+static int usefulFile(const char *dir, const char *basename)
{
- int l = strlen(a);
-
- if (strstr(a, "bin") || strstr(a, "/etc") || strncmp(a, "/lib", 4) == 0)
- return 1;
-
- if (l < 3)
- return 0;
+ if (strstr(dir, "bin/"))
+ return 1;
+ if (strstr(dir, "/etc/"))
+ return 1;
- if (strcmp(a + l - 3, ".so") == 0
- || strstr(a, ".so."))
- return 1;
+ const char *pos = strstr(basename, ".so");
+ if (pos > basename) {
+ int c = pos[3];
+ if (c == '.' || c == '\0')
+ return 1;
+ }
+
+ if (reqfiles.size() > 0) {
+ char fullname[strlen(dir) + strlen(basename) + 1];
+ strcpy(fullname, dir);
+ strcat(fullname, basename);
+ if (reqfiles.find(fullname) != reqfiles.end())
+ return 2;
+ }
+
return 0;
}
@@ -133,9 +145,8 @@ static void copyStrippedFileList(Header
{
int ok = 0;
- ok = usefullFile(basenames[i]);
- if (!ok)
- ok = usefullFile(dirnames[dirindexes[i]]);
+ ok = usefulFile(dirnames[dirindexes[i]], basenames[i]);
+ // if (ok > 1) cerr << "useful file: " << dirnames[dirindexes[i]] << basenames[i] <<endl;
if (!ok) {
int k = i;
@@ -599,6 +610,40 @@ int main(int argc, char ** argv)
int isSource;
#endif
+ if (!fullFileList) {
+ // first pass: initialize reqfiles
+ for (entry_cur = 0; entry_cur < entry_no; entry_cur++) {
+ fd = fdOpen(dirEntries[entry_cur]->d_name, O_RDONLY, 0666);
+ if (!fd)
+ continue;
+ int rc;
+ Header h;
+#if RPM_VERSION >= 0x040100
+ rc = rpmReadPackageFile(ts, fd, dirEntries[entry_cur]->d_name, &h);
+ if (rc == RPMRC_OK || rc == RPMRC_NOTTRUSTED || rc == RPMRC_NOKEY) {
+#else
+ rc = rpmReadPackageHeader(fd, &h, &isSource, NULL, NULL);
+ if (rc == 0) {
+#endif
+ int reqtype;
+ const char **requires;
+ int nreq;
+ rc = headerGetEntry(h, RPMTAG_REQUIRENAME, &reqtype, (void**)&requires, &nreq);
+ if (rc == 1 && reqtype == RPM_STRING_ARRAY_TYPE) {
+ int i;
+ for (i = 0; i < nreq; i++) {
+ const char *req = requires[i];
+ if (*req == '/') {
+ // cerr << dirEntries[entry_cur]->d_name << " requires " << req << endl;
+ reqfiles.insert(req);
+ }
+ }
+ }
+ headerFree(h);
+ }
+ Fclose(fd);
+ }
+ }
for (entry_cur = 0; entry_cur < entry_no; entry_cur++) {
struct stat sb;

View File

@ -62,12 +62,9 @@ Patch48: apt-0.5.15lorg2-alt-apt-get-TryToInstall-PrvPkgCandVer.patch
Patch49: apt-0.5.15lorg2-alt-apt-get-simple-output.patch
Patch50: apt-0.5.15lorg2-alt-versionmatch-TryToChangeVer.patch
Patch51: apt-0.5.15lorg2-alt-exit-status.patch
# Fix for bug #5400
Patch52: apt-0.5.15lorg2-alt-i18n-apt-shell-typo.patch
# Fix for bug #7618
Patch53: apt-0.5.15lorg2-alt-src-apt-shell-wrong_message_fix.patch
Patch54: apt-0.5.15lorg2-alt-genpkglist-reqfiles.patch
# Normally not applied, but useful.
Patch101: apt-0.5.4cnc9-alt-getsrc-debug.patch
@ -278,6 +275,7 @@ This package contains method 'rsync' for APT.
%patch51 -p1
%patch52 -p1
%patch53 -p1
%patch54 -p1
find -type f -name \*.orig -delete