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