]> git.ipfire.org Git - thirdparty/libsolv.git/commitdiff
add experimental pool_deb_get_autoinstalled
authorMichael Schroeder <mls@suse.de>
Tue, 3 Feb 2015 13:21:55 +0000 (14:21 +0100)
committerMichael Schroeder <mls@suse.de>
Tue, 3 Feb 2015 13:21:55 +0000 (14:21 +0100)
This can be used to read the autoinstalled package list from
/var/lib/apt/extended_states. Note that the pool must have
the whatprovides hash in place for this to work.

ext/libsolvext.ver
ext/repo_deb.c
ext/repo_deb.h

index 5c176e2cf53b892081b408480a151e482cf33013..654469b62aaac2b79500b28a48c4a98aa0d22d2f 100644 (file)
@@ -1,5 +1,6 @@
 SOLV_1.0 {
        global:
+               pool_deb_get_autoinstalled;
                pool_findfileconflicts;
                repo_add_appdata;
                repo_add_appdata_dir;
@@ -58,6 +59,7 @@ SOLV_1.0 {
                solvsig_free;
                solvsig_verify;
                testcase_add_testtags;
+               testcase_dep2str;
                testcase_job2str;
                testcase_solvid2str;
                testcase_str2dep;
index 4ddb8a3c36ae779051d4380a60460a556edb75da..c1ad9f5f081115a7b4c9b648ca1be07d926c8b50 100644 (file)
@@ -204,7 +204,7 @@ control2solvable(Solvable *s, Repodata *data, char *control)
       if (*p)
         *p++ = 0;
       /* strip trailing space */
-      while (end >= control && *end == ' ' && *end == '\t')
+      while (end >= control && (*end == ' ' || *end == '\t'))
        *end-- = 0;
       tag = control;
       control = p;
@@ -617,3 +617,87 @@ repo_add_deb(Repo *repo, const char *deb, int flags)
     repodata_internalize(data);
   return s - pool->solvables;
 }
+
+void
+pool_deb_get_autoinstalled(Pool *pool, FILE *fp, Queue *q)
+{
+  Id name = 0, arch = 0;
+  int autoinstalled = -1;
+  char *buf, *bp;
+  int x, l, bufl, eof = 0;
+  Id p, pp;
+
+  queue_empty(q);
+  buf = solv_malloc(4096);
+  bufl = 4096;
+  l = 0;
+  while (!eof)
+    {
+      while (bufl - l < 1024)
+       {
+         bufl += 4096;
+         if (bufl > 1024 * 64)
+           break;      /* hmm? */
+         buf = solv_realloc(buf, bufl);
+       }
+      if (!fgets(buf + l, bufl - l, fp))
+       {
+         eof = 1;
+         buf[l] = '\n';
+         buf[l + 1] = 0;
+       }
+      l = strlen(buf);
+      if (l && buf[l - 1] == '\n')
+       buf[--l] = 0;
+      if (!*buf || eof)
+       {
+         l = 0;
+         if (name && autoinstalled > 0)
+           {
+             FOR_PROVIDES(p, pp, name)
+               {
+                 Solvable *s = pool->solvables + p;
+                 if (s->name != name)
+                   continue;
+                 if (arch && s->arch != arch)
+                   continue;
+                 queue_push(q, p);
+               }
+           }
+         name = arch = 0;
+         autoinstalled = -1;
+         continue;
+       }
+      /* strip trailing space */
+      while (l && (buf[l - 1] == ' ' || buf[l - 1] == '\t'))
+       buf[--l] = 0;
+      l = 0;
+
+      bp = strchr(buf, ':');
+      if (!bp || bp - buf < 4)
+       continue;
+      *bp++ = 0;
+      while (*bp == ' ' || *bp == '\t')
+       bp++;
+      x = '@' + (buf[0] & 0x1f);
+      x = (x << 8) + '@' + (buf[1] & 0x1f);
+      switch(x)
+       {
+       case 'P' << 8 | 'A':
+         if (!strcasecmp(buf, "package"))
+           name = pool_str2id(pool, bp, 1);
+         break;
+       case 'A' << 8 | 'R':
+         if (!strcasecmp(buf, "architecture"))
+           arch = pool_str2id(pool, bp, 1);
+         break;
+       case 'A' << 8 | 'U':
+         if (!strcasecmp(buf, "auto-installed"))
+           autoinstalled = atoi(bp);
+         break;
+       default:
+         break;
+       }
+    }
+}
+
index 7057da68b00057a936ae2036e159053df1da4859..4303b0538c0b307683cd5d72d052a893fad907d9 100644 (file)
@@ -8,5 +8,6 @@
 extern int repo_add_debpackages(Repo *repo, FILE *fp, int flags);
 extern int repo_add_debdb(Repo *repo, int flags);
 extern Id repo_add_deb(Repo *repo, const char *deb, int flags);
+extern void pool_deb_get_autoinstalled(Pool *pool, FILE *fp, Queue *q);
 
 #define DEBS_ADD_WITH_PKGID    (1 << 8)