]>
Commit | Line | Data |
---|---|---|
d428d131 MV |
1 | // Include Files /*{{{*/ |
2 | #include <config.h> | |
3 | ||
d428d131 | 4 | #include <apt-pkg/acquire-item.h> |
453b82a3 DK |
5 | #include <apt-pkg/configuration.h> |
6 | #include <apt-pkg/error.h> | |
d428d131 | 7 | #include <apt-pkg/fileutl.h> |
453b82a3 DK |
8 | #include <apt-pkg/sourcelist.h> |
9 | #include <apt-pkg/acquire.h> | |
10 | #include <apt-pkg/strutl.h> | |
11 | #include <apt-pkg/update.h> | |
d428d131 | 12 | |
453b82a3 DK |
13 | #include <string> |
14 | #include <vector> | |
d428d131 MV |
15 | |
16 | #include <apti18n.h> | |
17 | /*}}}*/ | |
18 | ||
19 | using namespace std; | |
20 | ||
21 | // ListUpdate - construct Fetcher and update the cache files /*{{{*/ | |
22 | // --------------------------------------------------------------------- | |
23 | /* This is a simple wrapper to update the cache. it will fetch stuff | |
24 | * from the network (or any other sources defined in sources.list) | |
25 | */ | |
26 | bool ListUpdate(pkgAcquireStatus &Stat, | |
27 | pkgSourceList &List, | |
28 | int PulseInterval) | |
29 | { | |
04a54261 DK |
30 | pkgAcquire Fetcher(&Stat); |
31 | if (Fetcher.GetLock(_config->FindDir("Dir::State::Lists")) == false) | |
d428d131 MV |
32 | return false; |
33 | ||
34 | // Populate it with the source selection | |
35 | if (List.GetIndexes(&Fetcher) == false) | |
36 | return false; | |
37 | ||
38 | return AcquireUpdate(Fetcher, PulseInterval, true); | |
39 | } | |
40 | /*}}}*/ | |
41 | // AcquireUpdate - take Fetcher and update the cache files /*{{{*/ | |
42 | // --------------------------------------------------------------------- | |
43 | /* This is a simple wrapper to update the cache with a provided acquire | |
44 | * If you only need control over Status and the used SourcesList use | |
45 | * ListUpdate method instead. | |
46 | */ | |
47 | bool AcquireUpdate(pkgAcquire &Fetcher, int const PulseInterval, | |
48 | bool const RunUpdateScripts, bool const ListCleanup) | |
49 | { | |
50 | // Run scripts | |
51 | if (RunUpdateScripts == true) | |
52 | RunScripts("APT::Update::Pre-Invoke"); | |
53 | ||
54 | pkgAcquire::RunResult res; | |
55 | if(PulseInterval > 0) | |
56 | res = Fetcher.Run(PulseInterval); | |
57 | else | |
58 | res = Fetcher.Run(); | |
59 | ||
60 | if (res == pkgAcquire::Failed) | |
61 | return false; | |
62 | ||
63 | bool Failed = false; | |
64 | bool TransientNetworkFailure = false; | |
65 | for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); | |
66 | I != Fetcher.ItemsEnd(); ++I) | |
67 | { | |
68 | if ((*I)->Status == pkgAcquire::Item::StatDone) | |
69 | continue; | |
70 | ||
71 | (*I)->Finished(); | |
72 | ||
73 | ::URI uri((*I)->DescURI()); | |
74 | uri.User.clear(); | |
75 | uri.Password.clear(); | |
76 | string descUri = string(uri); | |
0efb29eb | 77 | _error->Warning(_("Failed to fetch %s %s"), descUri.c_str(), |
d428d131 MV |
78 | (*I)->ErrorText.c_str()); |
79 | ||
80 | if ((*I)->Status == pkgAcquire::Item::StatTransientNetworkError) | |
81 | { | |
82 | TransientNetworkFailure = true; | |
83 | continue; | |
84 | } | |
85 | ||
86 | Failed = true; | |
87 | } | |
88 | ||
89 | // Clean out any old list files | |
90 | // Keep "APT::Get::List-Cleanup" name for compatibility, but | |
91 | // this is really a global option for the APT library now | |
92 | if (!TransientNetworkFailure && !Failed && ListCleanup == true && | |
93 | (_config->FindB("APT::Get::List-Cleanup",true) == true && | |
94 | _config->FindB("APT::List-Cleanup",true) == true)) | |
95 | { | |
96 | if (Fetcher.Clean(_config->FindDir("Dir::State::lists")) == false || | |
97 | Fetcher.Clean(_config->FindDir("Dir::State::lists") + "partial/") == false) | |
98 | // something went wrong with the clean | |
99 | return false; | |
100 | } | |
101 | ||
102 | if (TransientNetworkFailure == true) | |
103 | _error->Warning(_("Some index files failed to download. They have been ignored, or old ones used instead.")); | |
104 | else if (Failed == true) | |
105 | return _error->Error(_("Some index files failed to download. They have been ignored, or old ones used instead.")); | |
106 | ||
107 | ||
108 | // Run the success scripts if all was fine | |
109 | if (RunUpdateScripts == true) | |
110 | { | |
111 | if(!TransientNetworkFailure && !Failed) | |
112 | RunScripts("APT::Update::Post-Invoke-Success"); | |
113 | ||
114 | // Run the other scripts | |
115 | RunScripts("APT::Update::Post-Invoke"); | |
116 | } | |
117 | return true; | |
118 | } | |
119 | /*}}}*/ |