]>
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>
29 // CacheFile::CacheFile - Constructor /*{{{*/
30 // ---------------------------------------------------------------------
32 pkgCacheFile::pkgCacheFile() : Map(NULL
), Cache(NULL
), DCache(NULL
),
33 SrcList(NULL
), Policy(NULL
)
37 // CacheFile::~CacheFile - Destructor /*{{{*/
38 // ---------------------------------------------------------------------
40 pkgCacheFile::~pkgCacheFile()
47 _system
->UnLock(true);
50 // CacheFile::BuildCaches - Open and build the cache files /*{{{*/
51 // ---------------------------------------------------------------------
53 bool pkgCacheFile::BuildCaches(OpProgress
*Progress
, bool WithLock
)
58 if (_config
->FindB("pkgCacheFile::Generate", true) == false)
60 Map
= new MMap(*new FileFd(_config
->FindFile("Dir::Cache::pkgcache"),
61 FileFd::ReadOnly
),MMap::Public
|MMap::ReadOnly
);
62 Cache
= new pkgCache(Map
);
63 if (_error
->PendingError() == true)
68 const bool ErrorWasEmpty
= _error
->empty();
70 if (_system
->Lock() == false)
73 if (_config
->FindB("Debug::NoLocking",false) == true)
76 if (_error
->PendingError() == true)
79 BuildSourceList(Progress
);
82 bool Res
= pkgCacheGenerator::MakeStatusCache(*SrcList
,Progress
,&Map
,!WithLock
);
86 return _error
->Error(_("The package lists or status file could not be parsed or opened."));
88 /* This sux, remove it someday */
89 if (ErrorWasEmpty
== true && _error
->empty() == false)
90 _error
->Warning(_("You may want to run apt-get update to correct these problems"));
92 Cache
= new pkgCache(Map
);
93 if (_error
->PendingError() == true)
98 // CacheFile::BuildSourceList - Open and build all relevant sources.list/*{{{*/
99 // ---------------------------------------------------------------------
101 bool pkgCacheFile::BuildSourceList(OpProgress
*Progress
)
106 SrcList
= new pkgSourceList();
107 if (SrcList
->ReadMainList() == false)
108 return _error
->Error(_("The list of sources could not be read."));
112 // CacheFile::BuildPolicy - Open and build all relevant preferences /*{{{*/
113 // ---------------------------------------------------------------------
115 bool pkgCacheFile::BuildPolicy(OpProgress
*Progress
)
120 Policy
= new pkgPolicy(Cache
);
121 if (_error
->PendingError() == true)
124 if (ReadPinFile(*Policy
) == false || ReadPinDir(*Policy
) == false)
130 // CacheFile::BuildDepCache - Open and build the dependency cache /*{{{*/
131 // ---------------------------------------------------------------------
133 bool pkgCacheFile::BuildDepCache(OpProgress
*Progress
)
138 DCache
= new pkgDepCache(Cache
,Policy
);
139 if (_error
->PendingError() == true)
142 DCache
->Init(Progress
);
146 // CacheFile::Open - Open the cache files, creating if necessary /*{{{*/
147 // ---------------------------------------------------------------------
149 bool pkgCacheFile::Open(OpProgress
*Progress
, bool WithLock
)
151 if (BuildCaches(Progress
,WithLock
) == false)
154 if (BuildPolicy(Progress
) == false)
157 if (BuildDepCache(Progress
) == false)
160 if (Progress
!= NULL
)
162 if (_error
->PendingError() == true)
168 // CacheFile::RemoveCaches - remove all cache files from disk /*{{{*/
169 // ---------------------------------------------------------------------
171 void pkgCacheFile::RemoveCaches()
173 std::string
const pkgcache
= _config
->FindFile("Dir::cache::pkgcache");
174 std::string
const srcpkgcache
= _config
->FindFile("Dir::cache::srcpkgcache");
176 if (pkgcache
.empty() == false && RealFileExists(pkgcache
) == true)
177 unlink(pkgcache
.c_str());
178 if (srcpkgcache
.empty() == false && RealFileExists(srcpkgcache
) == true)
179 unlink(srcpkgcache
.c_str());
182 // CacheFile::Close - close the cache files /*{{{*/
183 // ---------------------------------------------------------------------
185 void pkgCacheFile::Close()
192 _system
->UnLock(true);