]>
git.saurik.com Git - apt.git/blob - apt-pkg/cachefile.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: cachefile.cc,v 1.8 2002/04/27 04:28:04 jgg Exp $
4 /* ######################################################################
6 CacheFile - Simple wrapper class for opening, generating and whatnot
8 This class implements a simple 2 line mechanism to open various sorts
9 of caches. It can operate as root, as not root, show progress and so on,
10 it transparently handles everything necessary.
12 ##################################################################### */
14 // Include Files /*{{{*/
15 #include <apt-pkg/cachefile.h>
16 #include <apt-pkg/error.h>
17 #include <apt-pkg/sourcelist.h>
18 #include <apt-pkg/pkgcachegen.h>
19 #include <apt-pkg/configuration.h>
20 #include <apt-pkg/policy.h>
21 #include <apt-pkg/pkgsystem.h>
22 #include <apt-pkg/acquire-item.h>
23 #include <apt-pkg/fileutl.h>
27 // CacheFile::CacheFile - Constructor /*{{{*/
28 // ---------------------------------------------------------------------
30 pkgCacheFile::pkgCacheFile() : Map(NULL
), Cache(NULL
), DCache(NULL
),
31 Policy(NULL
), SrcList(NULL
)
35 // CacheFile::~CacheFile - Destructor /*{{{*/
36 // ---------------------------------------------------------------------
38 pkgCacheFile::~pkgCacheFile()
45 _system
->UnLock(true);
48 // CacheFile::BuildCaches - Open and build the cache files /*{{{*/
49 // ---------------------------------------------------------------------
51 bool pkgCacheFile::BuildCaches(OpProgress
*Progress
, bool WithLock
)
56 if (_config
->FindB("pkgCacheFile::Generate", true) == false)
58 Map
= new MMap(*new FileFd(_config
->FindFile("Dir::Cache::pkgcache"),
59 FileFd::ReadOnly
),MMap::Public
|MMap::ReadOnly
);
60 Cache
= new pkgCache(Map
);
61 if (_error
->PendingError() == true)
66 const bool ErrorWasEmpty
= _error
->empty();
68 if (_system
->Lock() == false)
71 if (_config
->FindB("Debug::NoLocking",false) == true)
74 if (_error
->PendingError() == true)
77 BuildSourceList(Progress
);
80 bool Res
= pkgCacheGenerator::MakeStatusCache(*SrcList
,Progress
,&Map
,!WithLock
);
84 return _error
->Error(_("The package lists or status file could not be parsed or opened."));
86 /* This sux, remove it someday */
87 if (ErrorWasEmpty
== true && _error
->empty() == false)
88 _error
->Warning(_("You may want to run apt-get update to correct these problems"));
90 Cache
= new pkgCache(Map
);
91 if (_error
->PendingError() == true)
96 // CacheFile::BuildSourceList - Open and build all relevant sources.list/*{{{*/
97 // ---------------------------------------------------------------------
99 bool pkgCacheFile::BuildSourceList(OpProgress
*Progress
)
104 SrcList
= new pkgSourceList();
105 if (SrcList
->ReadMainList() == false)
106 return _error
->Error(_("The list of sources could not be read."));
110 // CacheFile::BuildPolicy - Open and build all relevant preferences /*{{{*/
111 // ---------------------------------------------------------------------
113 bool pkgCacheFile::BuildPolicy(OpProgress
*Progress
)
118 Policy
= new pkgPolicy(Cache
);
119 if (_error
->PendingError() == true)
122 if (ReadPinFile(*Policy
) == false || ReadPinDir(*Policy
) == false)
128 // CacheFile::BuildDepCache - Open and build the dependency cache /*{{{*/
129 // ---------------------------------------------------------------------
131 bool pkgCacheFile::BuildDepCache(OpProgress
*Progress
)
136 DCache
= new pkgDepCache(Cache
,Policy
);
137 if (_error
->PendingError() == true)
140 DCache
->Init(Progress
);
144 // CacheFile::Open - Open the cache files, creating if necessary /*{{{*/
145 // ---------------------------------------------------------------------
147 bool pkgCacheFile::Open(OpProgress
*Progress
, bool WithLock
)
149 if (BuildCaches(Progress
,WithLock
) == false)
152 if (BuildPolicy(Progress
) == false)
155 if (BuildDepCache(Progress
) == false)
158 if (Progress
!= NULL
)
160 if (_error
->PendingError() == true)
166 // CacheFile::Close - close the cache files /*{{{*/
167 // ---------------------------------------------------------------------
169 void pkgCacheFile::Close()
176 _system
->UnLock(true);