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