]> git.saurik.com Git - apt.git/blob - apt-pkg/cachefile.cc
add a segfault handler to MMap to show the Cache-Limit message, which
[apt.git] / apt-pkg / cachefile.cc
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: cachefile.cc,v 1.8 2002/04/27 04:28:04 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 #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>
24
25 #include <apti18n.h>
26 /*}}}*/
27 // CacheFile::CacheFile - Constructor /*{{{*/
28 // ---------------------------------------------------------------------
29 /* */
30 pkgCacheFile::pkgCacheFile() : Map(0), Cache(0), DCache(0), Policy(0)
31 {
32 }
33 /*}}}*/
34 // CacheFile::~CacheFile - Destructor /*{{{*/
35 // ---------------------------------------------------------------------
36 /* */
37 pkgCacheFile::~pkgCacheFile()
38 {
39 delete DCache;
40 delete Policy;
41 delete Cache;
42 delete Map;
43 _system->UnLock(true);
44 }
45 /*}}}*/
46 // CacheFile::BuildCaches - Open and build the cache files /*{{{*/
47 // ---------------------------------------------------------------------
48 /* */
49 bool pkgCacheFile::BuildCaches(OpProgress &Progress,bool WithLock)
50 {
51 if (WithLock == true)
52 if (_system->Lock() == false)
53 return false;
54
55 if (_config->FindB("Debug::NoLocking",false) == true)
56 WithLock = false;
57
58 if (_error->PendingError() == true)
59 return false;
60
61 // Read the source list
62 pkgSourceList List;
63 if (List.ReadMainList() == false)
64 return _error->Error(_("The list of sources could not be read."));
65
66 // Read the caches
67 bool Res = pkgMakeStatusCache(List,Progress,&Map,!WithLock);
68 Progress.Done();
69 if (Res == false)
70 return _error->Error(_("The package lists or status file could not be parsed or opened."));
71
72 /* This sux, remove it someday */
73 if (_error->empty() == false)
74 _error->Warning(_("You may want to run apt-get update to correct these problems"));
75
76 Cache = new pkgCache(Map);
77 if (_error->PendingError() == true)
78 return false;
79 return true;
80 }
81 /*}}}*/
82 // CacheFile::Open - Open the cache files, creating if necessary /*{{{*/
83 // ---------------------------------------------------------------------
84 /* */
85 bool pkgCacheFile::Open(OpProgress &Progress,bool WithLock)
86 {
87 if (BuildCaches(Progress,WithLock) == false)
88 return false;
89
90 // The policy engine
91 Policy = new pkgPolicy(Cache);
92 if (_error->PendingError() == true)
93 return false;
94 if (ReadPinFile(*Policy) == false)
95 return false;
96
97 // Create the dependency cache
98 DCache = new pkgDepCache(Cache,Policy);
99 if (_error->PendingError() == true)
100 return false;
101
102 DCache->Init(&Progress);
103 Progress.Done();
104 if (_error->PendingError() == true)
105 return false;
106
107 return true;
108 }
109 /*}}}*/
110 // CacheFile::Close - close the cache files /*{{{*/
111 // ---------------------------------------------------------------------
112 /* */
113 void pkgCacheFile::Close()
114 {
115 delete DCache;
116 delete Policy;
117 delete Cache;
118 delete Map;
119 _system->UnLock(true);
120
121 Map = 0;
122 DCache = 0;
123 Policy = 0;
124 Cache = 0;
125 }
126 /*}}}*/