]>
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 AL |
26 | /*}}}*/ |
27 | ||
28 | // CacheFile::CacheFile - Constructor /*{{{*/ | |
29 | // --------------------------------------------------------------------- | |
30 | /* */ | |
b2e465d6 | 31 | pkgCacheFile::pkgCacheFile() : Map(0), Cache(0), DCache(0), Policy(0) |
2d11135a AL |
32 | { |
33 | } | |
34 | /*}}}*/ | |
b2e465d6 | 35 | // CacheFile::~CacheFile - Destructor /*{{{*/ |
2d11135a AL |
36 | // --------------------------------------------------------------------- |
37 | /* */ | |
38 | pkgCacheFile::~pkgCacheFile() | |
39 | { | |
b2e465d6 AL |
40 | delete DCache; |
41 | delete Policy; | |
2d11135a AL |
42 | delete Cache; |
43 | delete Map; | |
b2e465d6 | 44 | _system->UnLock(true); |
2d11135a AL |
45 | } |
46 | /*}}}*/ | |
0077d829 | 47 | // CacheFile::BuildCaches - Open and build the cache files /*{{{*/ |
2d11135a AL |
48 | // --------------------------------------------------------------------- |
49 | /* */ | |
0077d829 | 50 | bool pkgCacheFile::BuildCaches(OpProgress &Progress,bool WithLock) |
2d11135a AL |
51 | { |
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 | |
68 | bool Res = pkgMakeStatusCache(List,Progress,&Map,!WithLock); | |
69 | Progress.Done(); | |
70 | if (Res == false) | |
71 | return _error->Error(_("The package lists or status file could not be parsed or opened.")); | |
72 | ||
73 | /* This sux, remove it someday */ | |
74 | if (_error->empty() == false) | |
a7c835af | 75 | _error->Warning(_("You may want to run apt-get update to correct these problems")); |
b2e465d6 AL |
76 | |
77 | Cache = new pkgCache(Map); | |
78 | if (_error->PendingError() == true) | |
79 | return false; | |
0077d829 AL |
80 | return true; |
81 | } | |
82 | /*}}}*/ | |
83 | // CacheFile::Open - Open the cache files, creating if necessary /*{{{*/ | |
84 | // --------------------------------------------------------------------- | |
85 | /* */ | |
86 | bool pkgCacheFile::Open(OpProgress &Progress,bool WithLock) | |
87 | { | |
88 | if (BuildCaches(Progress,WithLock) == false) | |
89 | return false; | |
2d11135a | 90 | |
b2e465d6 AL |
91 | // The policy engine |
92 | Policy = new pkgPolicy(Cache); | |
93 | if (_error->PendingError() == true) | |
94 | return false; | |
95 | if (ReadPinFile(*Policy) == false) | |
96 | return false; | |
2d11135a AL |
97 | |
98 | // Create the dependency cache | |
b2e465d6 AL |
99 | DCache = new pkgDepCache(Cache,Policy); |
100 | if (_error->PendingError() == true) | |
101 | return false; | |
102 | ||
103 | DCache->Init(&Progress); | |
803fafcb | 104 | Progress.Done(); |
2d11135a AL |
105 | if (_error->PendingError() == true) |
106 | return false; | |
2d11135a AL |
107 | |
108 | return true; | |
109 | } | |
110 | /*}}}*/ | |
b2e465d6 | 111 | |
89b70b5a | 112 | |
b2e465d6 AL |
113 | // CacheFile::Close - close the cache files /*{{{*/ |
114 | // --------------------------------------------------------------------- | |
115 | /* */ | |
116 | void pkgCacheFile::Close() | |
117 | { | |
118 | delete DCache; | |
119 | delete Policy; | |
120 | delete Cache; | |
121 | delete Map; | |
122 | _system->UnLock(true); | |
123 | ||
124 | Map = 0; | |
125 | DCache = 0; | |
126 | Policy = 0; | |
127 | Cache = 0; | |
128 | } | |
129 | /*}}}*/ |