]>
git.saurik.com Git - apt.git/blob - apt-pkg/sourcelist.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: sourcelist.cc,v 1.13 1999/04/07 05:30:17 jgg Exp $
4 /* ######################################################################
8 ##################################################################### */
10 // Include Files /*{{{*/
12 #pragma implementation "apt-pkg/sourcelist.h"
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 <apt-pkg/strutl.h>
27 // SourceList::pkgSourceList - Constructors /*{{{*/
28 // ---------------------------------------------------------------------
30 pkgSourceList::pkgSourceList()
34 pkgSourceList::pkgSourceList(string File
)
39 // SourceList::ReadMainList - Read the main source list from etc /*{{{*/
40 // ---------------------------------------------------------------------
42 bool pkgSourceList::ReadMainList()
44 return Read(_config
->FindFile("Dir::Etc::sourcelist"));
47 // SourceList::Read - Parse the sourcelist file /*{{{*/
48 // ---------------------------------------------------------------------
50 bool pkgSourceList::Read(string File
)
52 // Open the stream for reading
53 ifstream
F(File
.c_str(),ios::in
| ios::nocreate
);
55 return _error
->Errno("ifstream::ifstream","Opening %s",File
.c_str());
57 List
.erase(List
.begin(),List
.end());
61 while (F
.eof() == false)
63 F
.getline(Buffer
,sizeof(Buffer
));
65 _strtabexpand(Buffer
,sizeof(Buffer
));
69 if (Buffer
[0] == '#' || Buffer
[0] == 0)
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());
88 // Check for an absolute dists specification.
89 if (Itm
.Dist
.empty() == false && Itm
.Dist
[Itm
.Dist
.size() - 1] == '/')
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"));
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());
106 while (ParseQuoteWord(C
,Itm
.Section
) == true);
111 // SourceList::Item << - Writes the item to a stream /*{{{*/
112 // ---------------------------------------------------------------------
113 /* This is not suitable for rebuilding the sourcelist file but it good for
115 ostream
&operator <<(ostream
&O
,pkgSourceList::Item
&Itm
)
117 O
<< (int)Itm
.Type
<< ' ' << Itm
.URI
<< ' ' << Itm
.Dist
<< ' ' << Itm
.Section
;
121 // SourceList::Item::SetType - Sets the distribution type /*{{{*/
122 // ---------------------------------------------------------------------
124 bool pkgSourceList::Item::SetType(string S
)
141 // SourceList::Item::SetURI - Set the URI /*{{{*/
142 // ---------------------------------------------------------------------
143 /* For simplicity we strip the scheme off the uri */
144 bool pkgSourceList::Item::SetURI(string S
)
146 if (S
.empty() == true)
149 if (S
.find(':') == string::npos
)
152 S
= SubstVar(S
,"$(ARCH)",_config
->Find("APT::Architecture"));
154 // Make sure that the URN is / postfixed
156 if (URI
[URI
.size() - 1] != '/')
162 // SourceList::Item::PackagesURI - Returns a URI to the packages file /*{{{*/
163 // ---------------------------------------------------------------------
165 string
pkgSourceList::Item::PackagesURI() const
171 if (Dist
[Dist
.size() - 1] == '/')
174 Res
= URI
+ "dists/" + Dist
+ '/' + Section
+
175 "/binary-" + _config
->Find("APT::Architecture") + '/';
181 if (Dist
[Dist
.size() - 1] == '/')
184 Res
= URI
+ "dists/" + Dist
+ '/' + Section
+
193 // SourceList::Item::PackagesInfo - Shorter version of the URI /*{{{*/
194 // ---------------------------------------------------------------------
195 /* This is a shorter version that is designed to be < 60 chars or so */
196 string
pkgSourceList::Item::PackagesInfo() const
202 Res
+= SiteOnly(URI
) + ' ';
203 if (Dist
[Dist
.size() - 1] == '/')
206 Res
+= Dist
+ '/' + Section
;
212 Res
+= SiteOnly(URI
) + ' ';
213 if (Dist
[Dist
.size() - 1] == '/')
216 Res
+= Dist
+ '/' + Section
;
224 // SourceList::Item::ReleaseURI - Returns a URI to the release file /*{{{*/
225 // ---------------------------------------------------------------------
227 string
pkgSourceList::Item::ReleaseURI() const
233 if (Dist
[Dist
.size() - 1] == '/')
236 Res
= URI
+ "dists/" + Dist
+ '/' + Section
+
237 "/binary-" + _config
->Find("APT::Architecture") + '/';
243 if (Dist
[Dist
.size() - 1] == '/')
246 Res
= URI
+ "dists/" + Dist
+ '/' + Section
+
255 // SourceList::Item::ReleaseInfo - Shorter version of the URI /*{{{*/
256 // ---------------------------------------------------------------------
257 /* This is a shorter version that is designed to be < 60 chars or so */
258 string
pkgSourceList::Item::ReleaseInfo() const
265 Res
+= SiteOnly(URI
) + ' ';
266 if (Dist
[Dist
.size() - 1] == '/')
269 Res
+= Dist
+ '/' + Section
;
277 // SourceList::Item::ArchiveInfo - Shorter version of the archive spec /*{{{*/
278 // ---------------------------------------------------------------------
279 /* This is a shorter version that is designed to be < 60 chars or so */
280 string
pkgSourceList::Item::ArchiveInfo(pkgCache::VerIterator Ver
) const
287 Res
+= SiteOnly(URI
) + ' ';
288 if (Dist
[Dist
.size() - 1] == '/')
291 Res
+= Dist
+ '/' + Section
;
294 Res
+= Ver
.ParentPkg().Name();
303 // SourceList::Item::ArchiveURI - Returns a URI to the given archive /*{{{*/
304 // ---------------------------------------------------------------------
306 string
pkgSourceList::Item::ArchiveURI(string File
) const
319 // SourceList::Item::SourceInfo - Returns an info line for a source /*{{{*/
320 // ---------------------------------------------------------------------
322 string
pkgSourceList::Item::SourceInfo(string Pkg
,string Ver
,string Comp
) const
329 Res
+= SiteOnly(URI
) + ' ';
330 if (Dist
[Dist
.size() - 1] == '/')
333 Res
+= Dist
+ '/' + Section
;
339 if (Comp
.empty() == false)
340 Res
+= " (" + Comp
+ ")";
346 // SourceList::Item::SiteOnly - Strip off the path part of a URI /*{{{*/
347 // ---------------------------------------------------------------------
349 string
pkgSourceList::Item::SiteOnly(string URI
) const
351 unsigned int Pos
= URI
.find(':');
352 if (Pos
== string::npos
|| Pos
+ 3 > URI
.length())
354 if (URI
[Pos
+ 1] != '/' || URI
[Pos
+ 2] != '/')
357 Pos
= URI
.find('/',Pos
+ 3);
358 if (Pos
== string::npos
)
360 return string(URI
,0,Pos
);