]> git.saurik.com Git - apt.git/blob - test/interactive-helper/testextract.cc
use forward declaration in headers if possible instead of includes
[apt.git] / test / interactive-helper / testextract.cc
1 #include <apt-pkg/dpkgdb.h>
2 #include <apt-pkg/debfile.h>
3 #include <apt-pkg/error.h>
4 #include <apt-pkg/configuration.h>
5 #include <apt-pkg/progress.h>
6 #include <apt-pkg/extract.h>
7 #include <apt-pkg/init.h>
8 #include <apt-pkg/strutl.h>
9 #include <apt-pkg/fileutl.h>
10 #include <apt-pkg/pkgsystem.h>
11
12 #include <stdio.h>
13 #include <stdlib.h>
14
15 using namespace std;
16
17 bool Go(int argc,char *argv[])
18 {
19 // Init the database
20 debDpkgDB Db;
21 {
22 OpTextProgress Prog;
23
24 if (Db.ReadyPkgCache(Prog) == false)
25 return false;
26 Prog.Done();
27
28 if (Db.ReadyFileList(Prog) == false)
29 return false;
30 }
31
32 for (int I = 1; I < argc; I++)
33 {
34 const char *Fake = 0;
35 for (unsigned J = 0; argv[I][J] != 0; J++)
36 {
37 if (argv[I][J] != ',')
38 continue;
39 Fake = argv[I] + J + 1;
40 argv[I][J] = 0;
41 }
42
43 FileFd F(argv[I],FileFd::ReadOnly);
44 debDebFile Deb(F);
45
46 if (_error->PendingError() == true)
47 return false;
48
49 if (Deb.ExtractControl(Db) == false)
50 return false;
51 cout << argv[I] << endl;
52
53 pkgCache::VerIterator Ver = Deb.MergeControl(Db);
54 if (Ver.end() == true)
55 return false;
56
57 cout << Ver.ParentPkg().Name() << ' ' << Ver.VerStr() << endl;
58
59 pkgExtract Extract(Db.GetFLCache(),Ver);
60
61 if (Fake != 0)
62 {
63 pkgExtract::Item Itm;
64 memset(&Itm,0,sizeof(Itm));
65 FILE *F = fopen(Fake,"r");
66 while (feof(F) == 0)
67 {
68 char Line[300];
69 fgets(Line,sizeof(Line),F);
70 Itm.Name = _strstrip(Line);
71 Itm.Type = pkgDirStream::Item::File;
72 if (Line[strlen(Line)-1] == '/')
73 Itm.Type = pkgDirStream::Item::Directory;
74
75 int Fd;
76 if (Extract.DoItem(Itm,Fd) == false) {
77 fclose(F);
78 return false;
79 }
80 }
81 fclose(F);
82 }
83 else
84 if (Deb.ExtractArchive(Extract) == false)
85 return false;
86 }
87 return true;
88 }
89
90 int main(int argc,char *argv[])
91 {
92 pkgInitConfig(*_config);
93 pkgInitSystem(*_config,_system);
94 _config->Set("Dir::State::status","/tmp/testing/status");
95
96 Go(argc,argv);
97
98 if (_error->PendingError() == true)
99 {
100 _error->DumpErrors();
101 return 0;
102 }
103 }