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