]> git.saurik.com Git - apt.git/blob - apt-pkg/cachefile.cc
Purge support
[apt.git] / apt-pkg / cachefile.cc
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: cachefile.cc,v 1.4 1999/06/24 04:06:30 jgg Exp $
4 /* ######################################################################
5
6 CacheFile - Simple wrapper class for opening, generating and whatnot
7
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.
11
12 ##################################################################### */
13 /*}}}*/
14 // Include Files /*{{{*/
15 #ifdef __GNUG__
16 #pragma implementation "apt-pkg/cachefile.h"
17 #endif
18
19 #include <apt-pkg/cachefile.h>
20 #include <apt-pkg/error.h>
21 #include <apt-pkg/sourcelist.h>
22 #include <apt-pkg/pkgcachegen.h>
23 #include <apt-pkg/configuration.h>
24 /*}}}*/
25
26 // CacheFile::CacheFile - Constructor /*{{{*/
27 // ---------------------------------------------------------------------
28 /* */
29 pkgCacheFile::pkgCacheFile() : Map(0), Cache(0), Lock(0)
30 {
31 }
32 /*}}}*/
33 // CacheFile::~CacheFile - Destructor /*{{{*/
34 // ---------------------------------------------------------------------
35 /* */
36 pkgCacheFile::~pkgCacheFile()
37 {
38 delete Cache;
39 delete Map;
40 delete Lock;
41 }
42 /*}}}*/
43 // CacheFile::Open - Open the cache files, creating if necessary /*{{{*/
44 // ---------------------------------------------------------------------
45 /* */
46 bool pkgCacheFile::Open(OpProgress &Progress,bool WithLock)
47 {
48 if (WithLock == true)
49 Lock = new pkgDpkgLock;
50
51 if (_error->PendingError() == true)
52 return false;
53
54 // Read the source list
55 pkgSourceList List;
56 if (List.ReadMainList() == false)
57 return _error->Error("The list of sources could not be read.");
58
59 /* Build all of the caches, using the cache files if we are locking
60 (ie as root) */
61 if (WithLock == true)
62 {
63 pkgMakeStatusCache(List,Progress);
64 Progress.Done();
65 if (_error->PendingError() == true)
66 return _error->Error("The package lists or status file could not be parsed or opened.");
67 if (_error->empty() == false)
68 _error->Warning("You may want to run apt-get update to correct these missing files");
69
70 // Open the cache file
71 FileFd File(_config->FindFile("Dir::Cache::pkgcache"),FileFd::ReadOnly);
72 if (_error->PendingError() == true)
73 return false;
74
75 Map = new MMap(File,MMap::Public | MMap::ReadOnly);
76 if (_error->PendingError() == true)
77 return false;
78 }
79 else
80 {
81 Map = pkgMakeStatusCacheMem(List,Progress);
82 Progress.Done();
83 if (Map == 0)
84 return false;
85 }
86
87 // Create the dependency cache
88 Cache = new pkgDepCache(*Map,Progress);
89 Progress.Done();
90 if (_error->PendingError() == true)
91 return false;
92
93 return true;
94 }
95 /*}}}*/