]>
git.saurik.com Git - apt.git/blob - apt-pkg/sourcelist.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: sourcelist.cc,v 1.3 1998/07/12 23:58:36 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>
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
->Find("APT::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::SanitizeURI - Hash the uri /*{{{*/
112 // ---------------------------------------------------------------------
113 /* This converts a URI into a safe filename. It quotes all unsafe characters
114 and converts / to _ and removes the scheme identifier. */
115 string
pkgSourceList::SanitizeURI(string URI
)
117 string::const_iterator I
= URI
.begin() + URI
.find(':') + 1;
118 for (; I
< URI
.end() && *I
== '/'; I
++);
120 // "\x00-\x20{}|\\\\^\\[\\]<>\"\x7F-\xFF";
121 URI
= QuoteString(string(I
,URI
.end() - I
),"\\|{}[]<>\"^~_=!@#$%^&*");
122 string::iterator J
= URI
.begin();
123 for (; J
!= URI
.end(); J
++)
129 // SourceList::MatchPkgFile - Find the package file that has the ver /*{{{*/
130 // ---------------------------------------------------------------------
131 /* This will return List.end() if it could not find the matching
133 pkgSourceList::const_iterator
pkgSourceList::MatchPkgFile(pkgCache::VerIterator Ver
)
135 string Base
= _config
->Find("APT::Architecture");
136 for (const_iterator I
= List
.begin(); I
!= List
.end(); I
++)
138 string URI
= I
->PackagesURI();
142 /* if (Base + SanitizeURI(URI) == Ver.File().FileName())
150 // SourceList::Item << - Writes the item to a stream /*{{{*/
151 // ---------------------------------------------------------------------
152 /* This is not suitable for rebuilding the sourcelist file but it good for
154 ostream
&operator <<(ostream
&O
,pkgSourceList::Item
&Itm
)
156 O
<< Itm
.Type
<< ' ' << Itm
.URI
<< ' ' << Itm
.Dist
<< ' ' << Itm
.Section
;
160 // SourceList::Item::SetType - Sets the distribution type /*{{{*/
161 // ---------------------------------------------------------------------
163 bool pkgSourceList::Item::SetType(string S
)
174 // SourceList::Item::SetURI - Set the URI /*{{{*/
175 // ---------------------------------------------------------------------
176 /* For simplicity we strip the scheme off the uri */
177 bool pkgSourceList::Item::SetURI(string S
)
179 if (S
.empty() == true)
182 if (S
.find(':') == string::npos
)
185 S
= SubstVar(S
,"$(ARCH)",_config
->Find("APT::Architecture"));
187 // Make sure that the URN is / postfixed
189 if (URI
[URI
.size() - 1] != '/')
195 // SourceList::Item::PackagesURI - Returns a URI to the packages file /*{{{*/
196 // ---------------------------------------------------------------------
198 string
pkgSourceList::Item::PackagesURI() const
204 if (Dist
[Dist
.size() - 1] == '/')
207 Res
= URI
+ "dists/" + Dist
+ '/' + Section
+
208 "/binary-" + _config
->Find("APT::Architecture") + '/';
216 // SourceList::Item::PackagesInfo - Shorter version of the URI /*{{{*/
217 // ---------------------------------------------------------------------
218 /* This is a shorter version that is designed to be < 60 chars or so */
219 string
pkgSourceList::Item::PackagesInfo() const
225 Res
+= SiteOnly(URI
) + ' ';
226 if (Dist
[Dist
.size() - 1] == '/')
229 Res
+= Dist
+ '/' + Section
;
237 // SourceList::Item::ArchiveInfo - Shorter version of the archive spec /*{{{*/
238 // ---------------------------------------------------------------------
239 /* This is a shorter version that is designed to be < 60 chars or so */
240 string
pkgSourceList::Item::ArchiveInfo(pkgCache::VerIterator Ver
) const
246 Res
+= SiteOnly(URI
) + ' ';
247 if (Dist
[Dist
.size() - 1] == '/')
250 Res
+= Dist
+ '/' + Section
;
253 Res
+= Ver
.ParentPkg().Name();
259 // SourceList::Item::ArchiveURI - Returns a URI to the given archive /*{{{*/
260 // ---------------------------------------------------------------------
262 string
pkgSourceList::Item::ArchiveURI(string File
) const
274 // SourceList::Item::SiteOnly - Strip off the path part of a URI /*{{{*/
275 // ---------------------------------------------------------------------
277 string
pkgSourceList::Item::SiteOnly(string URI
) const
279 unsigned int Pos
= URI
.find(':');
280 if (Pos
== string::npos
|| Pos
+ 3 > URI
.length())
282 if (URI
[Pos
+ 1] != '/' || URI
[Pos
+ 2] != '/')
285 Pos
= URI
.find('/',Pos
+ 3);
286 if (Pos
== string::npos
)
288 return string(URI
,0,Pos
);