]>
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 /*{{{*/
17 #include <apt-pkg/cachefile.h>
18 #include <apt-pkg/error.h>
19 #include <apt-pkg/sourcelist.h>
20 #include <apt-pkg/pkgcachegen.h>
21 #include <apt-pkg/configuration.h>
22 #include <apt-pkg/policy.h>
23 #include <apt-pkg/pkgsystem.h>
24 #include <apt-pkg/acquire-item.h>
25 #include <apt-pkg/fileutl.h>
26 #include <apt-pkg/progress.h>
30 // CacheFile::CacheFile - Constructor /*{{{*/
31 // ---------------------------------------------------------------------
33 pkgCacheFile::pkgCacheFile() : Map(NULL
), Cache(NULL
), DCache(NULL
),
34 SrcList(NULL
), Policy(NULL
)
38 // CacheFile::~CacheFile - Destructor /*{{{*/
39 // ---------------------------------------------------------------------
41 pkgCacheFile::~pkgCacheFile()
48 _system
->UnLock(true);
51 // CacheFile::BuildCaches - Open and build the cache files /*{{{*/
52 // ---------------------------------------------------------------------
54 bool pkgCacheFile::BuildCaches(OpProgress
*Progress
, bool WithLock
)
59 if (_config
->FindB("pkgCacheFile::Generate", true) == false)
61 Map
= new MMap(*new FileFd(_config
->FindFile("Dir::Cache::pkgcache"),
62 FileFd::ReadOnly
),MMap::Public
|MMap::ReadOnly
);
63 Cache
= new pkgCache(Map
);
64 if (_error
->PendingError() == true)
69 const bool ErrorWasEmpty
= _error
->empty();
71 if (_system
->Lock() == false)
74 if (_config
->FindB("Debug::NoLocking",false) == true)
77 if (_error
->PendingError() == true)
80 BuildSourceList(Progress
);
83 bool Res
= pkgCacheGenerator::MakeStatusCache(*SrcList
,Progress
,&Map
,!WithLock
);
87 return _error
->Error(_("The package lists or status file could not be parsed or opened."));
89 /* This sux, remove it someday */
90 if (ErrorWasEmpty
== true && _error
->empty() == false)
91 _error
->Warning(_("You may want to run apt-get update to correct these problems"));
93 Cache
= new pkgCache(Map
);
94 if (_error
->PendingError() == true)
99 // CacheFile::BuildSourceList - Open and build all relevant sources.list/*{{{*/
100 // ---------------------------------------------------------------------
102 bool pkgCacheFile::BuildSourceList(OpProgress
*Progress
)
107 SrcList
= new pkgSourceList();
108 if (SrcList
->ReadMainList() == false)
109 return _error
->Error(_("The list of sources could not be read."));
113 // CacheFile::BuildPolicy - Open and build all relevant preferences /*{{{*/
114 // ---------------------------------------------------------------------
116 bool pkgCacheFile::BuildPolicy(OpProgress
*Progress
)
121 Policy
= new pkgPolicy(Cache
);
122 if (_error
->PendingError() == true)
125 if (ReadPinFile(*Policy
) == false || ReadPinDir(*Policy
) == false)
131 // CacheFile::BuildDepCache - Open and build the dependency cache /*{{{*/
132 // ---------------------------------------------------------------------
134 bool pkgCacheFile::BuildDepCache(OpProgress
*Progress
)
139 DCache
= new pkgDepCache(Cache
,Policy
);
140 if (_error
->PendingError() == true)
143 DCache
->Init(Progress
);
147 // CacheFile::Open - Open the cache files, creating if necessary /*{{{*/
148 // ---------------------------------------------------------------------
150 bool pkgCacheFile::Open(OpProgress
*Progress
, bool WithLock
)
152 if (BuildCaches(Progress
,WithLock
) == false)
155 if (BuildPolicy(Progress
) == false)
158 if (BuildDepCache(Progress
) == false)
161 if (Progress
!= NULL
)
163 if (_error
->PendingError() == true)
169 // CacheFile::RemoveCaches - remove all cache files from disk /*{{{*/
170 // ---------------------------------------------------------------------
172 void pkgCacheFile::RemoveCaches()
174 std::string
const pkgcache
= _config
->FindFile("Dir::cache::pkgcache");
175 std::string
const srcpkgcache
= _config
->FindFile("Dir::cache::srcpkgcache");
177 if (pkgcache
.empty() == false && RealFileExists(pkgcache
) == true)
178 unlink(pkgcache
.c_str());
179 if (srcpkgcache
.empty() == false && RealFileExists(srcpkgcache
) == true)
180 unlink(srcpkgcache
.c_str());
183 // CacheFile::Close - close the cache files /*{{{*/
184 // ---------------------------------------------------------------------
186 void pkgCacheFile::Close()
193 _system
->UnLock(true);