1 | // pkg_acqfile.cc |
---|
2 | // |
---|
3 | // Copyright 2002 Daniel Burrows |
---|
4 | // |
---|
5 | // This program is free software; you can redistribute it and/or modify |
---|
6 | // it under the terms of the GNU General Public License as published by |
---|
7 | // the Free Software Foundation; either version 2 of the License, or |
---|
8 | // (at your option) any later version. |
---|
9 | // |
---|
10 | // This program is distributed in the hope that it will be useful, |
---|
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
13 | // GNU General Public License for more details. |
---|
14 | // |
---|
15 | // You should have received a copy of the GNU General Public License |
---|
16 | // along with this program; see the file COPYING. If not, write to |
---|
17 | // the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
18 | // Boston, MA 02111-1307, USA. |
---|
19 | |
---|
20 | // (based on pkg_changelog) |
---|
21 | // |
---|
22 | // mvo: taken from aptitude with a big _thankyou_ |
---|
23 | |
---|
24 | #include "pkg_acqfile.h" |
---|
25 | |
---|
26 | #include "config.h" |
---|
27 | #include "i18n.h" |
---|
28 | |
---|
29 | #include <stdio.h> |
---|
30 | #include <errno.h> |
---|
31 | #include <unistd.h> |
---|
32 | #include <fcntl.h> |
---|
33 | #include <signal.h> |
---|
34 | #include <sys/stat.h> |
---|
35 | |
---|
36 | #include <apt-pkg/error.h> |
---|
37 | #include <apt-pkg/configuration.h> |
---|
38 | #include <apt-pkg/acquire-item.h> |
---|
39 | #include <apt-pkg/sourcelist.h> |
---|
40 | #include <apt-pkg/strutl.h> |
---|
41 | |
---|
42 | // Let's all sing a song about apt-pkg's brokenness.. |
---|
43 | |
---|
44 | pkgAcqFileSane::pkgAcqFileSane(pkgAcquire *Owner, string URI, |
---|
45 | string Description, string ShortDesc, |
---|
46 | string filename): |
---|
47 | Item(Owner) |
---|
48 | { |
---|
49 | Retries=_config->FindI("Acquire::Retries",0); |
---|
50 | DestFile=filename; |
---|
51 | |
---|
52 | Desc.URI=URI; |
---|
53 | Desc.Description=Description; |
---|
54 | Desc.Owner=this; |
---|
55 | Desc.ShortDesc=ShortDesc; |
---|
56 | |
---|
57 | QueueURI(Desc); |
---|
58 | } |
---|
59 | |
---|
60 | // Straight from acquire-item.cc |
---|
61 | /* Here we try other sources */ |
---|
62 | void pkgAcqFileSane::Failed(string Message,pkgAcquire::MethodConfig *Cnf) |
---|
63 | { |
---|
64 | ErrorText = LookupTag(Message,"Message"); |
---|
65 | |
---|
66 | // This is the retry counter |
---|
67 | if (Retries != 0 && |
---|
68 | Cnf->LocalOnly == false && |
---|
69 | StringToBool(LookupTag(Message,"Transient-Failure"),false) == true) |
---|
70 | { |
---|
71 | Retries--; |
---|
72 | QueueURI(Desc); |
---|
73 | return; |
---|
74 | } |
---|
75 | |
---|
76 | Item::Failed(Message,Cnf); |
---|
77 | } |
---|
78 | |
---|
79 | // Mostly copied from pkgAcqArchive. |
---|
80 | bool get_archive(pkgAcquire *Owner, pkgSourceList *Sources, |
---|
81 | pkgRecords *Recs, pkgCache::VerIterator const &Version, |
---|
82 | string directory, string &StoreFilename) |
---|
83 | { |
---|
84 | pkgCache::VerFileIterator Vf=Version.FileList(); |
---|
85 | |
---|
86 | if(Version.Arch()==0) |
---|
87 | return _error->Error(_("I wasn't able to locate a file for the %s package. " |
---|
88 | "This might mean you need to manually fix this package. (due to missing arch)"), |
---|
89 | Version.ParentPkg().Name()); |
---|
90 | |
---|
91 | /* We need to find a filename to determine the extension. We make the |
---|
92 | assumption here that all the available sources for this version share |
---|
93 | the same extension.. */ |
---|
94 | // Skip not source sources, they do not have file fields. |
---|
95 | for (; Vf.end() == false; Vf++) |
---|
96 | { |
---|
97 | if ((Vf.File()->Flags & pkgCache::Flag::NotSource) != 0) |
---|
98 | continue; |
---|
99 | break; |
---|
100 | } |
---|
101 | |
---|
102 | // Does not really matter here.. we are going to fail out below |
---|
103 | if (Vf.end() != true) |
---|
104 | { |
---|
105 | // If this fails to get a file name we will bomb out below. |
---|
106 | pkgRecords::Parser &Parse = Recs->Lookup(Vf); |
---|
107 | if (_error->PendingError() == true) |
---|
108 | return false; |
---|
109 | |
---|
110 | // Generate the final file name as: package_version_arch.foo |
---|
111 | StoreFilename = QuoteString(Version.ParentPkg().Name(),"_:") + '_' + |
---|
112 | QuoteString(Version.VerStr(),"_:") + '_' + |
---|
113 | QuoteString(Version.Arch(),"_:.") + |
---|
114 | "." + flExtension(Parse.FileName()); |
---|
115 | } |
---|
116 | |
---|
117 | for (; Vf.end() == false; Vf++) |
---|
118 | { |
---|
119 | // Ignore not source sources |
---|
120 | if ((Vf.File()->Flags & pkgCache::Flag::NotSource) != 0) |
---|
121 | continue; |
---|
122 | |
---|
123 | // Try to cross match against the source list |
---|
124 | pkgIndexFile *Index; |
---|
125 | if (Sources->FindIndex(Vf.File(),Index) == false) |
---|
126 | continue; |
---|
127 | |
---|
128 | // Grab the text package record |
---|
129 | pkgRecords::Parser &Parse = Recs->Lookup(Vf); |
---|
130 | if (_error->PendingError() == true) |
---|
131 | return false; |
---|
132 | |
---|
133 | string PkgFile = Parse.FileName(); |
---|
134 | if (PkgFile.empty() == true) |
---|
135 | return _error->Error(_("The package index files are corrupted. No Filename: " |
---|
136 | "field for package %s."), |
---|
137 | Version.ParentPkg().Name()); |
---|
138 | |
---|
139 | string DestFile = directory + "/" + flNotDir(StoreFilename); |
---|
140 | |
---|
141 | // Create the item |
---|
142 | new pkgAcqFileSane(Owner, Index->ArchiveURI(PkgFile), |
---|
143 | Index->ArchiveInfo(Version), |
---|
144 | Version.ParentPkg().Name(), DestFile); |
---|
145 | |
---|
146 | Vf++; |
---|
147 | return true; |
---|
148 | } |
---|
149 | return false; |
---|
150 | } |
---|