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