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