]> git.saurik.com Git - apt.git/blame_incremental - apt-pkg/sourcelist.cc
Add ldconfig to postinst script under configure argument
[apt.git] / apt-pkg / sourcelist.cc
... / ...
CommitLineData
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
3// $Id: sourcelist.cc,v 1.9 1998/12/10 04:22:47 jgg Exp $
4/* ######################################################################
5
6 List of Sources
7
8 ##################################################################### */
9 /*}}}*/
10// Include Files /*{{{*/
11#ifdef __GNUG__
12#pragma implementation "apt-pkg/sourcelist.h"
13#endif
14
15#include <apt-pkg/sourcelist.h>
16#include <apt-pkg/error.h>
17#include <apt-pkg/fileutl.h>
18#include <apt-pkg/configuration.h>
19#include <strutl.h>
20
21#include <fstream.h>
22#include <stdio.h>
23#include <unistd.h>
24#include <sys/stat.h>
25 /*}}}*/
26
27// SourceList::pkgSourceList - Constructors /*{{{*/
28// ---------------------------------------------------------------------
29/* */
30pkgSourceList::pkgSourceList()
31{
32}
33
34pkgSourceList::pkgSourceList(string File)
35{
36 Read(File);
37}
38 /*}}}*/
39// SourceList::ReadMainList - Read the main source list from etc /*{{{*/
40// ---------------------------------------------------------------------
41/* */
42bool pkgSourceList::ReadMainList()
43{
44 return Read(_config->FindFile("Dir::Etc::sourcelist"));
45}
46 /*}}}*/
47// SourceList::Read - Parse the sourcelist file /*{{{*/
48// ---------------------------------------------------------------------
49/* */
50bool pkgSourceList::Read(string File)
51{
52 // Open the stream for reading
53 ifstream F(File.c_str(),ios::in | ios::nocreate);
54 if (!F != 0)
55 return _error->Errno("ifstream::ifstream","Opening %s",File.c_str());
56
57 List.erase(List.begin(),List.end());
58 char Buffer[300];
59
60 int CurLine = 0;
61 while (F.eof() == false)
62 {
63 F.getline(Buffer,sizeof(Buffer));
64 CurLine++;
65 _strtabexpand(Buffer,sizeof(Buffer));
66 _strstrip(Buffer);
67
68 // Comment or blank
69 if (Buffer[0] == '#' || Buffer[0] == 0)
70 continue;
71
72 // Grok it
73 string Type;
74 string URI;
75 Item Itm;
76 char *C = Buffer;
77 if (ParseQuoteWord(C,Type) == false)
78 return _error->Error("Malformed line %u in source list %s (type)",CurLine,File.c_str());
79 if (ParseQuoteWord(C,URI) == false)
80 return _error->Error("Malformed line %u in source list %s (URI)",CurLine,File.c_str());
81 if (ParseQuoteWord(C,Itm.Dist) == false)
82 return _error->Error("Malformed line %u in source list %s (dist)",CurLine,File.c_str());
83 if (Itm.SetType(Type) == false)
84 return _error->Error("Malformed line %u in source list %s (type parse)",CurLine,File.c_str());
85 if (Itm.SetURI(URI) == false)
86 return _error->Error("Malformed line %u in source list %s (URI parse)",CurLine,File.c_str());
87
88 // Check for an absolute dists specification.
89 if (Itm.Dist.empty() == false && Itm.Dist[Itm.Dist.size() - 1] == '/')
90 {
91 if (ParseQuoteWord(C,Itm.Section) == true)
92 return _error->Error("Malformed line %u in source list %s (Absolute dist)",CurLine,File.c_str());
93 Itm.Dist = SubstVar(Itm.Dist,"$(ARCH)",_config->Find("APT::Architecture"));
94 List.push_back(Itm);
95 continue;
96 }
97
98 // Grab the rest of the dists
99 if (ParseQuoteWord(C,Itm.Section) == false)
100 return _error->Error("Malformed line %u in source list %s (dist parse)",CurLine,File.c_str());
101
102 do
103 {
104 List.push_back(Itm);
105 }
106 while (ParseQuoteWord(C,Itm.Section) == true);
107 }
108 return true;
109}
110 /*}}}*/
111// SourceList::Item << - Writes the item to a stream /*{{{*/
112// ---------------------------------------------------------------------
113/* This is not suitable for rebuilding the sourcelist file but it good for
114 debugging. */
115ostream &operator <<(ostream &O,pkgSourceList::Item &Itm)
116{
117 O << (int)Itm.Type << ' ' << Itm.URI << ' ' << Itm.Dist << ' ' << Itm.Section;
118 return O;
119}
120 /*}}}*/
121// SourceList::Item::SetType - Sets the distribution type /*{{{*/
122// ---------------------------------------------------------------------
123/* */
124bool pkgSourceList::Item::SetType(string S)
125{
126 if (S == "deb")
127 {
128 Type = Deb;
129 return true;
130 }
131
132 return true;
133}
134 /*}}}*/
135// SourceList::Item::SetURI - Set the URI /*{{{*/
136// ---------------------------------------------------------------------
137/* For simplicity we strip the scheme off the uri */
138bool pkgSourceList::Item::SetURI(string S)
139{
140 if (S.empty() == true)
141 return false;
142
143 if (S.find(':') == string::npos)
144 return false;
145
146 S = SubstVar(S,"$(ARCH)",_config->Find("APT::Architecture"));
147
148 // Make sure that the URN is / postfixed
149 URI = S;
150 if (URI[URI.size() - 1] != '/')
151 URI += '/';
152
153 return true;
154}
155 /*}}}*/
156// SourceList::Item::PackagesURI - Returns a URI to the packages file /*{{{*/
157// ---------------------------------------------------------------------
158/* */
159string pkgSourceList::Item::PackagesURI() const
160{
161 string Res;
162 switch (Type)
163 {
164 case Deb:
165 if (Dist[Dist.size() - 1] == '/')
166 Res = URI + Dist;
167 else
168 Res = URI + "dists/" + Dist + '/' + Section +
169 "/binary-" + _config->Find("APT::Architecture") + '/';
170
171 Res += "Packages";
172 break;
173 };
174 return Res;
175}
176 /*}}}*/
177// SourceList::Item::PackagesInfo - Shorter version of the URI /*{{{*/
178// ---------------------------------------------------------------------
179/* This is a shorter version that is designed to be < 60 chars or so */
180string pkgSourceList::Item::PackagesInfo() const
181{
182 string Res;
183 switch (Type)
184 {
185 case Deb:
186 Res += SiteOnly(URI) + ' ';
187 if (Dist[Dist.size() - 1] == '/')
188 Res += Dist;
189 else
190 Res += Dist + '/' + Section;
191
192 Res += " Packages";
193 break;
194 };
195 return Res;
196}
197 /*}}}*/
198// SourceList::Item::ReleaseURI - Returns a URI to the release file /*{{{*/
199// ---------------------------------------------------------------------
200/* */
201string pkgSourceList::Item::ReleaseURI() const
202{
203 string Res;
204 switch (Type)
205 {
206 case Deb:
207 if (Dist[Dist.size() - 1] == '/')
208 Res = URI + Dist;
209 else
210 Res = URI + "dists/" + Dist + '/' + Section +
211 "/binary-" + _config->Find("APT::Architecture") + '/';
212
213 Res += "Release";
214 break;
215 };
216 return Res;
217}
218 /*}}}*/
219// SourceList::Item::ReleaseInfo - Shorter version of the URI /*{{{*/
220// ---------------------------------------------------------------------
221/* This is a shorter version that is designed to be < 60 chars or so */
222string pkgSourceList::Item::ReleaseInfo() const
223{
224 string Res;
225 switch (Type)
226 {
227 case Deb:
228 Res += SiteOnly(URI) + ' ';
229 if (Dist[Dist.size() - 1] == '/')
230 Res += Dist;
231 else
232 Res += Dist + '/' + Section;
233
234 Res += " Release";
235 break;
236 };
237 return Res;
238}
239 /*}}}*/
240// SourceList::Item::ArchiveInfo - Shorter version of the archive spec /*{{{*/
241// ---------------------------------------------------------------------
242/* This is a shorter version that is designed to be < 60 chars or so */
243string pkgSourceList::Item::ArchiveInfo(pkgCache::VerIterator Ver) const
244{
245 string Res;
246 switch (Type)
247 {
248 case Deb:
249 Res += SiteOnly(URI) + ' ';
250 if (Dist[Dist.size() - 1] == '/')
251 Res += Dist;
252 else
253 Res += Dist + '/' + Section;
254
255 Res += " ";
256 Res += Ver.ParentPkg().Name();
257 Res += " ";
258 Res += Ver.VerStr();
259
260 break;
261 };
262 return Res;
263}
264 /*}}}*/
265// SourceList::Item::ArchiveURI - Returns a URI to the given archive /*{{{*/
266// ---------------------------------------------------------------------
267/* */
268string pkgSourceList::Item::ArchiveURI(string File) const
269{
270 string Res;
271 switch (Type)
272 {
273 case Deb:
274 Res = URI + File;
275 break;
276 };
277 return Res;
278}
279 /*}}}*/
280// SourceList::Item::SiteOnly - Strip off the path part of a URI /*{{{*/
281// ---------------------------------------------------------------------
282/* */
283string pkgSourceList::Item::SiteOnly(string URI) const
284{
285 unsigned int Pos = URI.find(':');
286 if (Pos == string::npos || Pos + 3 > URI.length())
287 return URI;
288 if (URI[Pos + 1] != '/' || URI[Pos + 2] != '/')
289 return URI;
290
291 Pos = URI.find('/',Pos + 3);
292 if (Pos == string::npos)
293 return URI;
294 return string(URI,0,Pos);
295}
296 /*}}}*/