]>
git.saurik.com Git - apt.git/blob - apt-pkg/pkgcachegen.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: pkgcachegen.cc,v 1.1 1998/07/02 02:58:12 jgg Exp $
4 /* ######################################################################
6 Package Cache Generator - Generator for the cache structure.
8 This builds the cache structure from the abstract package list parser.
10 ##################################################################### */
12 // Include Files /*{{{*/
13 #include <pkglib/pkgcachegen.h>
14 #include <pkglib/error.h>
15 #include <pkglib/version.h>
21 // CacheGenerator::pkgCacheGenerator - Constructor /*{{{*/
22 // ---------------------------------------------------------------------
23 /* We set the diry flag and make sure that is written to the disk */
24 pkgCacheGenerator::pkgCacheGenerator(DynamicMMap
&Map
) : Map(Map
), Cache(Map
)
26 if (_error
->PendingError() == true)
31 Map
.RawAllocate(sizeof(pkgCache::Header
));
32 *Cache
.HeaderP
= pkgCache::Header();
34 Cache
.HeaderP
->Dirty
= true;
35 Map
.Sync(0,sizeof(pkgCache::Header
));
36 Map
.UsePools(*Cache
.HeaderP
->Pools
,sizeof(Cache
.HeaderP
->Pools
)/sizeof(Cache
.HeaderP
->Pools
[0]));
39 // CacheGenerator::~pkgCacheGenerator - Destructor /*{{{*/
40 // ---------------------------------------------------------------------
41 /* We sync the data then unset the dirty flag in two steps so as to
42 advoid a problem during a crash */
43 pkgCacheGenerator::~pkgCacheGenerator()
45 if (_error
->PendingError() == true)
47 if (Map
.Sync() == false)
50 Cache
.HeaderP
->Dirty
= false;
51 Map
.Sync(0,sizeof(pkgCache::Header
));
54 // CacheGenerator::MergeList - Merge the package list /*{{{*/
55 // ---------------------------------------------------------------------
56 /* This provides the generation of the entries in the cache. Each loop
57 goes through a single package record from the underlying parse engine. */
58 bool pkgCacheGenerator::MergeList(ListParser
&List
)
64 // Get a pointer to the package structure
65 string Package
= List
.Package();
66 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(Package
);
67 if (Pkg
.end() == false)
69 if (NewPackage(Pkg
,Package
) == false)
72 if (List
.NewPackage(Pkg
) == false)
75 if (List
.UsePackage(Pkg
) == false)
78 /* Get a pointer to the version structure. We know the list is sorted
79 so we use that fact in the search. Insertion of new versions is
80 done with correct sorting */
81 string Version
= List
.Version();
82 pkgCache::VerIterator Ver
= Pkg
.VersionList();
83 unsigned long *Last
= &Pkg
->VersionList
;
85 for (; Ver
.end() == false; Ver
++, Last
= &Ver
->NextVer
)
87 Res
= pkgVersionCompare(Version
.begin(),Version
.end(),Ver
.VerStr(),
88 Ver
.VerStr() + strlen(Ver
.VerStr()));
93 /* We already have a version for this item, record that we
97 if (NewFileVer(Ver
,List
) == false)
104 *Last
= NewVersion(Ver
,*Last
);
105 if (List
.NewVersion(Ver
) == false)
108 if (NewFileVer(Ver
,List
) == false)
111 while (List
.Step() == true);
116 // CacheGenerator::NewPackage - Add a new package /*{{{*/
117 // ---------------------------------------------------------------------
118 /* This creates a new package structure and adds it to the hash table */
119 bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator Pkg
,string Name
)
122 unsigned long Package
= Map
.Allocate(sizeof(pkgCache::Package
));
126 Pkg
= pkgCache::PkgIterator(Cache
,Cache
.PackageP
+ Package
);
128 // Insert it into the hash table
129 unsigned long Hash
= Map
.Hash(Name
);
130 Pkg
->NextPackage
= Cache
.HeaderP
->HashTable
[Hash
];
131 Cache
.HeaderP
->HashTable
[Hash
] = Package
;
133 // Set the name and the ID
134 Pkg
->Name
= Map
.WriteString(Name
);
137 Pkg
->ID
= Cache
.HeaderP
->PackageCount
++;
142 // CacheGenerator::NewFileVer - Create a new File<->Version association /*{{{*/
143 // ---------------------------------------------------------------------
145 bool pkgCacheGenerator::NewFileVer(pkgCache::VerIterator Ver
,
150 // CacheGenerator::NewVersion - Create a new Version /*{{{*/
151 // ---------------------------------------------------------------------
153 unsigned long pkgCacheGenerator::NewVersion(pkgCache::VerIterator
&Ver
,
158 // CacheGenerator::SelectFile - Select the current file being parsed /*{{{*/
159 // ---------------------------------------------------------------------
160 /* This is used to select which file is to be associated with all newly
162 bool pkgCacheGenerator::SelectFile(string File
,unsigned long Flags
)
165 if (stat(File
.c_str(),&Buf
) == -1)
166 return _error
->Errno("stat","Couldn't stat ",File
.c_str());
168 // Get some space for the structure
169 CurrentFile
= Cache
.PkgFileP
+ Map
.Allocate(sizeof(*CurrentFile
));
170 if (CurrentFile
== Cache
.PkgFileP
)
174 CurrentFile
->FileName
= Map
.WriteString(File
);
175 CurrentFile
->Size
= Buf
.st_size
;
176 CurrentFile
->mtime
= Buf
.st_mtime
;
177 CurrentFile
->NextFile
= Cache
.HeaderP
->FileList
;
178 CurrentFile
->Flags
= Flags
;
181 if (CurrentFile
->FileName
== 0)