Fixed or handling bug
[ntk/apt.git] / test / scratch.cc
CommitLineData
421c8d10
AL
1#include <apt-pkg/dpkgdb.h>
2#include <apt-pkg/debfile.h>
2fd65468 3#include <apt-pkg/error.h>
421c8d10
AL
4#include <apt-pkg/configuration.h>
5#include <apt-pkg/progress.h>
6#include <apt-pkg/extract.h>
2fd65468 7#include <apt-pkg/init.h>
421c8d10 8#include <apt-pkg/fileutl.h>
b98f2859 9
93bf083d 10int main(int argc,char *argv[])
024835dc 11{
2fd65468 12 pkgInitialize(*_config);
421c8d10 13
eac03193 14// cout << flNoLink(argv[1]) << endl;
421c8d10 15
eac03193 16// #if 0
421c8d10
AL
17/* DynamicMMap *FileMap = new DynamicMMap(MMap::Public);
18 pkgFLCache *FList = new pkgFLCache(*FileMap);
19
20 char *Name = "/tmp/test";
21 pkgFLCache::PkgIterator Pkg(*FList,0);
22 pkgFLCache::NodeIterator Node = FList->GetNode(Name,Name+strlen(Name),Pkg.Offset(),true,false);
23 cout << (pkgFLCache::Node *)Node << endl;
24 Node = FList->GetNode(Name,Name+strlen(Name),Pkg.Offset(),true,false);
25 cout << (pkgFLCache::Node *)Node << endl;
26*/
27// #if 0
28 _config->Set("Dir::State::status","/tmp/testing/status");
29
30 debDpkgDB Db;
31
32 {
33 OpTextProgress Prog;
34
35 if (Db.ReadyPkgCache(Prog) == false)
36 cerr << "Error!" << endl;
37 Prog.Done();
38
39 if (Db.ReadyFileList(Prog) == false)
40 cerr << "Error!" << endl;
41 }
42
43 if (_error->PendingError() == true)
2fd65468
AL
44 {
45 _error->DumpErrors();
46 return 0;
47 }
48
421c8d10
AL
49/* Db.GetFLCache().BeginDiverLoad();
50 pkgFLCache::PkgIterator Pkg(Db.GetFLCache(),0);
51 if (Db.GetFLCache().AddDiversion(Pkg,"/usr/include/linux/kerneld.h","/usr/bin/nslookup") == false)
52 cerr << "Error!" << endl;
53
54 const char *Tmp = "/usr/include/linux/kerneld.h";
55 pkgFLCache::NodeIterator Nde = Db.GetFLCache().GetNode(Tmp,Tmp+strlen(Tmp),0,false,false);
56 map_ptrloc Loc = Nde->File;
57
58 for (; Nde.end() == false && Nde->File == Loc; Nde++)
59 cout << Nde->Flags << ',' << Nde->Pointer << ',' << Nde.File() << endl;
60 Db.GetFLCache().FinishDiverLoad();*/
61
62/* unsigned int I = 0;
63 pkgFLCache &Fl = Db.GetFLCache();
64 while (I < Fl.HeaderP->HashSize)
65 {
66 cout << I << endl;
67 pkgFLCache::NodeIterator Node(Fl,Fl.NodeP + Fl.HeaderP->FileHash + I++);
68 if (Node->Pointer == 0)
69 continue;
70 for (; Node.end() == false; Node++)
71 {
72 cout << Node.DirN() << '/' << Node.File();
73 if (Node->Flags == pkgFLCache::Node::Diversion)
74 cout << " (div)";
75 if (Node->Flags == pkgFLCache::Node::ConfFile)
76 cout << " (conf)";
77 cout << endl;
78 }
79 }*/
80
81 for (int I = 1; I < argc; I++)
2fd65468 82 {
421c8d10
AL
83 FileFd F(argv[I],FileFd::ReadOnly);
84 debDebFile Deb(F);
2fd65468 85
421c8d10
AL
86 if (Deb.ExtractControl(Db) == false)
87 cerr << "Error!" << endl;
88 cout << argv[I] << endl;
2fd65468 89
421c8d10
AL
90 pkgCache::VerIterator Ver = Deb.MergeControl(Db);
91 if (Ver.end() == true)
92 cerr << "Failed" << endl;
93 else
94 cout << Ver.ParentPkg().Name() << ' ' << Ver.VerStr() << endl;
2fd65468 95
421c8d10
AL
96 pkgExtract Extract(Db.GetFLCache(),Ver);
97 Deb.ExtractArchive(Extract);
2fd65468 98 }
421c8d10 99// #endif
eac03193 100//#endif
421c8d10 101 _error->DumpErrors();
024835dc 102}