summaryrefslogtreecommitdiff
path: root/test/interactive-helper/testextract.cc
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2011-09-14 13:22:19 +0200
committerMichael Vogt <michael.vogt@ubuntu.com>2011-09-14 13:22:19 +0200
commita0e07f3ec885c12c733c12805391646c202f3f31 (patch)
treefaa658f29d7dff42c6ed475037dd462384eab46e /test/interactive-helper/testextract.cc
parentb11fe392b2245354591296df88c3be2e6218af12 (diff)
parentafd7b358f94efddb83a2911ec1a21e7280074b1e (diff)
merged from lp:~donkult/apt/experimental
Diffstat (limited to 'test/interactive-helper/testextract.cc')
-rw-r--r--test/interactive-helper/testextract.cc101
1 files changed, 101 insertions, 0 deletions
diff --git a/test/interactive-helper/testextract.cc b/test/interactive-helper/testextract.cc
new file mode 100644
index 000000000..b790df618
--- /dev/null
+++ b/test/interactive-helper/testextract.cc
@@ -0,0 +1,101 @@
+#include <apt-pkg/dpkgdb.h>
+#include <apt-pkg/debfile.h>
+#include <apt-pkg/error.h>
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/progress.h>
+#include <apt-pkg/extract.h>
+#include <apt-pkg/init.h>
+#include <apt-pkg/strutl.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+using namespace std;
+
+bool Go(int argc,char *argv[])
+{
+ // Init the database
+ debDpkgDB Db;
+ {
+ OpTextProgress Prog;
+
+ if (Db.ReadyPkgCache(Prog) == false)
+ return false;
+ Prog.Done();
+
+ if (Db.ReadyFileList(Prog) == false)
+ return false;
+ }
+
+ for (int I = 1; I < argc; I++)
+ {
+ const char *Fake = 0;
+ for (unsigned J = 0; argv[I][J] != 0; J++)
+ {
+ if (argv[I][J] != ',')
+ continue;
+ Fake = argv[I] + J + 1;
+ argv[I][J] = 0;
+ }
+
+ FileFd F(argv[I],FileFd::ReadOnly);
+ debDebFile Deb(F);
+
+ if (_error->PendingError() == true)
+ return false;
+
+ if (Deb.ExtractControl(Db) == false)
+ return false;
+ cout << argv[I] << endl;
+
+ pkgCache::VerIterator Ver = Deb.MergeControl(Db);
+ if (Ver.end() == true)
+ return false;
+
+ cout << Ver.ParentPkg().Name() << ' ' << Ver.VerStr() << endl;
+
+ pkgExtract Extract(Db.GetFLCache(),Ver);
+
+ if (Fake != 0)
+ {
+ pkgExtract::Item Itm;
+ memset(&Itm,0,sizeof(Itm));
+ FILE *F = fopen(Fake,"r");
+ while (feof(F) == 0)
+ {
+ char Line[300];
+ fgets(Line,sizeof(Line),F);
+ Itm.Name = _strstrip(Line);
+ Itm.Type = pkgDirStream::Item::File;
+ if (Line[strlen(Line)-1] == '/')
+ Itm.Type = pkgDirStream::Item::Directory;
+
+ int Fd;
+ if (Extract.DoItem(Itm,Fd) == false) {
+ fclose(F);
+ return false;
+ }
+ }
+ fclose(F);
+ }
+ else
+ if (Deb.ExtractArchive(Extract) == false)
+ return false;
+ }
+ return true;
+}
+
+int main(int argc,char *argv[])
+{
+ pkgInitConfig(*_config);
+ pkgInitSystem(*_config,_system);
+ _config->Set("Dir::State::status","/tmp/testing/status");
+
+ Go(argc,argv);
+
+ if (_error->PendingError() == true)
+ {
+ _error->DumpErrors();
+ return 0;
+ }
+}