]>
Commit | Line | Data |
---|---|---|
2d11135a AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
0077d829 | 3 | // $Id: cachefile.cc,v 1.8 2002/04/27 04:28:04 jgg Exp $ |
2d11135a AL |
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 /*{{{*/ | |
2d11135a AL |
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> | |
b2e465d6 AL |
20 | #include <apt-pkg/policy.h> |
21 | #include <apt-pkg/pkgsystem.h> | |
89b70b5a | 22 | #include <apt-pkg/acquire-item.h> |
614adaa0 | 23 | #include <apt-pkg/fileutl.h> |
b2e465d6 AL |
24 | |
25 | #include <apti18n.h> | |
2d11135a | 26 | /*}}}*/ |
2d11135a AL |
27 | // CacheFile::CacheFile - Constructor /*{{{*/ |
28 | // --------------------------------------------------------------------- | |
29 | /* */ | |
b2e465d6 | 30 | pkgCacheFile::pkgCacheFile() : Map(0), Cache(0), DCache(0), Policy(0) |
2d11135a AL |
31 | { |
32 | } | |
33 | /*}}}*/ | |
b2e465d6 | 34 | // CacheFile::~CacheFile - Destructor /*{{{*/ |
2d11135a AL |
35 | // --------------------------------------------------------------------- |
36 | /* */ | |
37 | pkgCacheFile::~pkgCacheFile() | |
38 | { | |
b2e465d6 AL |
39 | delete DCache; |
40 | delete Policy; | |
2d11135a AL |
41 | delete Cache; |
42 | delete Map; | |
b2e465d6 | 43 | _system->UnLock(true); |
2d11135a AL |
44 | } |
45 | /*}}}*/ | |
0077d829 | 46 | // CacheFile::BuildCaches - Open and build the cache files /*{{{*/ |
2d11135a AL |
47 | // --------------------------------------------------------------------- |
48 | /* */ | |
2e5f4e45 | 49 | bool pkgCacheFile::BuildCaches(OpProgress *Progress, bool WithLock) |
2d11135a | 50 | { |
6009e60d | 51 | const bool ErrorWasEmpty = _error->empty(); |
2d11135a | 52 | if (WithLock == true) |
b2e465d6 AL |
53 | if (_system->Lock() == false) |
54 | return false; | |
2d11135a | 55 | |
c37b9502 AL |
56 | if (_config->FindB("Debug::NoLocking",false) == true) |
57 | WithLock = false; | |
58 | ||
2d11135a AL |
59 | if (_error->PendingError() == true) |
60 | return false; | |
61 | ||
62 | // Read the source list | |
63 | pkgSourceList List; | |
64 | if (List.ReadMainList() == false) | |
b2e465d6 AL |
65 | return _error->Error(_("The list of sources could not be read.")); |
66 | ||
67 | // Read the caches | |
2e5f4e45 DK |
68 | bool Res = pkgCacheGenerator::MakeStatusCache(List,Progress,&Map,!WithLock); |
69 | if (Progress != NULL) | |
70 | Progress->Done(); | |
b2e465d6 AL |
71 | if (Res == false) |
72 | return _error->Error(_("The package lists or status file could not be parsed or opened.")); | |
73 | ||
74 | /* This sux, remove it someday */ | |
6009e60d | 75 | if (ErrorWasEmpty == true && _error->empty() == false) |
a7c835af | 76 | _error->Warning(_("You may want to run apt-get update to correct these problems")); |
b2e465d6 AL |
77 | |
78 | Cache = new pkgCache(Map); | |
79 | if (_error->PendingError() == true) | |
80 | return false; | |
0077d829 AL |
81 | return true; |
82 | } | |
83 | /*}}}*/ | |
2e5f4e45 | 84 | // CacheFile::BuildPolicy - Open and build all relevant preferences /*{{{*/ |
0077d829 AL |
85 | // --------------------------------------------------------------------- |
86 | /* */ | |
2e5f4e45 | 87 | bool pkgCacheFile::BuildPolicy(OpProgress *Progress) |
0077d829 | 88 | { |
b2e465d6 AL |
89 | Policy = new pkgPolicy(Cache); |
90 | if (_error->PendingError() == true) | |
91 | return false; | |
6009e60d | 92 | |
e68ca100 | 93 | if (ReadPinFile(*Policy) == false || ReadPinDir(*Policy) == false) |
b2e465d6 | 94 | return false; |
2e5f4e45 DK |
95 | |
96 | return true; | |
97 | } | |
98 | /*}}}*/ | |
99 | // CacheFile::BuildDepCache - Open and build the dependency cache /*{{{*/ | |
100 | // --------------------------------------------------------------------- | |
101 | /* */ | |
102 | bool pkgCacheFile::BuildDepCache(OpProgress *Progress) | |
103 | { | |
b2e465d6 AL |
104 | DCache = new pkgDepCache(Cache,Policy); |
105 | if (_error->PendingError() == true) | |
106 | return false; | |
2e5f4e45 DK |
107 | |
108 | DCache->Init(Progress); | |
109 | return true; | |
110 | } | |
111 | /*}}}*/ | |
112 | // CacheFile::Open - Open the cache files, creating if necessary /*{{{*/ | |
113 | // --------------------------------------------------------------------- | |
114 | /* */ | |
115 | bool pkgCacheFile::Open(OpProgress *Progress, bool WithLock) | |
116 | { | |
117 | if (BuildCaches(Progress,WithLock) == false) | |
118 | return false; | |
119 | ||
120 | if (BuildPolicy(Progress) == false) | |
121 | return false; | |
122 | ||
123 | if (BuildDepCache(Progress) == false) | |
124 | return false; | |
125 | ||
126 | if (Progress != NULL) | |
127 | Progress->Done(); | |
2d11135a AL |
128 | if (_error->PendingError() == true) |
129 | return false; | |
2d11135a AL |
130 | |
131 | return true; | |
132 | } | |
133 | /*}}}*/ | |
b2e465d6 AL |
134 | // CacheFile::Close - close the cache files /*{{{*/ |
135 | // --------------------------------------------------------------------- | |
136 | /* */ | |
137 | void pkgCacheFile::Close() | |
138 | { | |
139 | delete DCache; | |
140 | delete Policy; | |
141 | delete Cache; | |
142 | delete Map; | |
143 | _system->UnLock(true); | |
144 | ||
145 | Map = 0; | |
146 | DCache = 0; | |
147 | Policy = 0; | |
148 | Cache = 0; | |
149 | } | |
150 | /*}}}*/ |