]>
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 /*{{{*/ | |
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> | |
b2e465d6 AL |
24 | #include <apt-pkg/policy.h> |
25 | #include <apt-pkg/pkgsystem.h> | |
89b70b5a | 26 | #include <apt-pkg/acquire-item.h> |
614adaa0 | 27 | #include <apt-pkg/fileutl.h> |
b2e465d6 AL |
28 | |
29 | #include <apti18n.h> | |
2d11135a AL |
30 | /*}}}*/ |
31 | ||
32 | // CacheFile::CacheFile - Constructor /*{{{*/ | |
33 | // --------------------------------------------------------------------- | |
34 | /* */ | |
b2e465d6 | 35 | pkgCacheFile::pkgCacheFile() : Map(0), Cache(0), DCache(0), Policy(0) |
2d11135a AL |
36 | { |
37 | } | |
38 | /*}}}*/ | |
b2e465d6 | 39 | // CacheFile::~CacheFile - Destructor /*{{{*/ |
2d11135a AL |
40 | // --------------------------------------------------------------------- |
41 | /* */ | |
42 | pkgCacheFile::~pkgCacheFile() | |
43 | { | |
b2e465d6 AL |
44 | delete DCache; |
45 | delete Policy; | |
2d11135a AL |
46 | delete Cache; |
47 | delete Map; | |
b2e465d6 | 48 | _system->UnLock(true); |
2d11135a AL |
49 | } |
50 | /*}}}*/ | |
0077d829 | 51 | // CacheFile::BuildCaches - Open and build the cache files /*{{{*/ |
2d11135a AL |
52 | // --------------------------------------------------------------------- |
53 | /* */ | |
0077d829 | 54 | bool pkgCacheFile::BuildCaches(OpProgress &Progress,bool WithLock) |
2d11135a AL |
55 | { |
56 | if (WithLock == true) | |
b2e465d6 AL |
57 | if (_system->Lock() == false) |
58 | return false; | |
2d11135a | 59 | |
c37b9502 AL |
60 | if (_config->FindB("Debug::NoLocking",false) == true) |
61 | WithLock = false; | |
62 | ||
2d11135a AL |
63 | if (_error->PendingError() == true) |
64 | return false; | |
65 | ||
66 | // Read the source list | |
67 | pkgSourceList List; | |
68 | if (List.ReadMainList() == false) | |
b2e465d6 AL |
69 | return _error->Error(_("The list of sources could not be read.")); |
70 | ||
71 | // Read the caches | |
72 | bool Res = pkgMakeStatusCache(List,Progress,&Map,!WithLock); | |
73 | Progress.Done(); | |
74 | if (Res == false) | |
75 | return _error->Error(_("The package lists or status file could not be parsed or opened.")); | |
76 | ||
77 | /* This sux, remove it someday */ | |
78 | if (_error->empty() == false) | |
a7c835af | 79 | _error->Warning(_("You may want to run apt-get update to correct these problems")); |
b2e465d6 AL |
80 | |
81 | Cache = new pkgCache(Map); | |
82 | if (_error->PendingError() == true) | |
83 | return false; | |
0077d829 AL |
84 | return true; |
85 | } | |
86 | /*}}}*/ | |
87 | // CacheFile::Open - Open the cache files, creating if necessary /*{{{*/ | |
88 | // --------------------------------------------------------------------- | |
89 | /* */ | |
90 | bool pkgCacheFile::Open(OpProgress &Progress,bool WithLock) | |
91 | { | |
92 | if (BuildCaches(Progress,WithLock) == false) | |
93 | return false; | |
2d11135a | 94 | |
b2e465d6 AL |
95 | // The policy engine |
96 | Policy = new pkgPolicy(Cache); | |
97 | if (_error->PendingError() == true) | |
98 | return false; | |
99 | if (ReadPinFile(*Policy) == false) | |
100 | return false; | |
2d11135a AL |
101 | |
102 | // Create the dependency cache | |
b2e465d6 AL |
103 | DCache = new pkgDepCache(Cache,Policy); |
104 | if (_error->PendingError() == true) | |
105 | return false; | |
106 | ||
107 | DCache->Init(&Progress); | |
803fafcb | 108 | Progress.Done(); |
2d11135a AL |
109 | if (_error->PendingError() == true) |
110 | return false; | |
2d11135a AL |
111 | |
112 | return true; | |
113 | } | |
114 | /*}}}*/ | |
b2e465d6 | 115 | |
89b70b5a MV |
116 | // CacheFile::ListUpdate - update the cache files /*{{{*/ |
117 | // --------------------------------------------------------------------- | |
118 | /* */ | |
119 | bool pkgCacheFile::ListUpdate(pkgAcquireStatus &Stat, pkgSourceList &List) | |
120 | { | |
121 | pkgAcquire Fetcher(&Stat); | |
122 | ||
123 | // Populate it with the source selection | |
124 | if (List.GetIndexes(&Fetcher) == false) | |
125 | return false; | |
126 | ||
614adaa0 MV |
127 | // Run scripts |
128 | RunScripts("APT::Update::Pre-Invoke"); | |
129 | ||
89b70b5a MV |
130 | // Run it |
131 | if (Fetcher.Run() == pkgAcquire::Failed) | |
132 | return false; | |
133 | ||
134 | bool Failed = false; | |
135 | for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); I++) | |
136 | { | |
137 | if ((*I)->Status == pkgAcquire::Item::StatDone) | |
138 | continue; | |
139 | ||
140 | (*I)->Finished(); | |
141 | ||
142 | _error->Warning(_("Failed to fetch %s %s\n"), | |
143 | (*I)->DescURI().c_str(), | |
144 | (*I)->ErrorText.c_str()); | |
145 | Failed = true; | |
146 | } | |
147 | ||
148 | // Clean out any old list files (if it was not a failure) | |
149 | // Keep "APT::Get::List-Cleanup" name for compatibility, but | |
150 | // this is really a global option for the APT library now | |
151 | if (!Failed && (_config->FindB("APT::Get::List-Cleanup",true) == true || | |
152 | _config->FindB("APT::List-Cleanup",true) == true)) | |
153 | { | |
154 | if (Fetcher.Clean(_config->FindDir("Dir::State::lists")) == false || | |
155 | Fetcher.Clean(_config->FindDir("Dir::State::lists") + "partial/") == false) | |
156 | return false; | |
157 | } | |
158 | ||
614adaa0 MV |
159 | // Run the scripts |
160 | RunScripts("APT::Update::Post-Invoke"); | |
89b70b5a MV |
161 | |
162 | return (Failed == false); | |
163 | } | |
164 | /*}}}*/ | |
165 | ||
b2e465d6 AL |
166 | // CacheFile::Close - close the cache files /*{{{*/ |
167 | // --------------------------------------------------------------------- | |
168 | /* */ | |
169 | void pkgCacheFile::Close() | |
170 | { | |
171 | delete DCache; | |
172 | delete Policy; | |
173 | delete Cache; | |
174 | delete Map; | |
175 | _system->UnLock(true); | |
176 | ||
177 | Map = 0; | |
178 | DCache = 0; | |
179 | Policy = 0; | |
180 | Cache = 0; | |
181 | } | |
182 | /*}}}*/ |