]>
git.saurik.com Git - apt.git/blob - apt-pkg/sourcelist.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: sourcelist.cc,v 1.3 2002/08/15 20:51:37 niemeyer Exp $
4 /* ######################################################################
8 ##################################################################### */
10 // Include Files /*{{{*/
11 #include <apt-pkg/sourcelist.h>
12 #include <apt-pkg/error.h>
13 #include <apt-pkg/fileutl.h>
14 #include <apt-pkg/strutl.h>
15 #include <apt-pkg/configuration.h>
24 // Global list of Items supported
25 static pkgSourceList::Type
*ItmList
[10];
26 pkgSourceList::Type
**pkgSourceList::Type::GlobalList
= ItmList
;
27 unsigned long pkgSourceList::Type::GlobalListLen
= 0;
29 // Type::Type - Constructor /*{{{*/
30 // ---------------------------------------------------------------------
31 /* Link this to the global list of items*/
32 pkgSourceList::Type::Type()
34 ItmList
[GlobalListLen
] = this;
38 // Type::GetType - Get a specific meta for a given type /*{{{*/
39 // ---------------------------------------------------------------------
41 pkgSourceList::Type
*pkgSourceList::Type::GetType(const char *Type
)
43 for (unsigned I
= 0; I
!= GlobalListLen
; I
++)
44 if (strcmp(GlobalList
[I
]->Name
,Type
) == 0)
49 // Type::FixupURI - Normalize the URI and check it.. /*{{{*/
50 // ---------------------------------------------------------------------
52 bool pkgSourceList::Type::FixupURI(string
&URI
) const
54 if (URI
.empty() == true)
57 if (URI
.find(':') == string::npos
)
60 URI
= SubstVar(URI
,"$(ARCH)",_config
->Find("APT::Architecture"));
62 // Make sure that the URI is / postfixed
63 if (URI
[URI
.size() - 1] != '/')
69 // Type::ParseLine - Parse a single line /*{{{*/
70 // ---------------------------------------------------------------------
71 /* This is a generic one that is the 'usual' format for sources.list
72 Weird types may override this. */
73 bool pkgSourceList::Type::ParseLine(vector
<metaIndex
*> &List
,
75 unsigned long CurLine
,
82 if (ParseQuoteWord(Buffer
,URI
) == false)
83 return _error
->Error(_("Malformed line %lu in source list %s (URI)"),CurLine
,File
.c_str());
84 if (ParseQuoteWord(Buffer
,Dist
) == false)
85 return _error
->Error(_("Malformed line %lu in source list %s (dist)"),CurLine
,File
.c_str());
87 if (FixupURI(URI
) == false)
88 return _error
->Error(_("Malformed line %lu in source list %s (URI parse)"),CurLine
,File
.c_str());
90 // Check for an absolute dists specification.
91 if (Dist
.empty() == false && Dist
[Dist
.size() - 1] == '/')
93 if (ParseQuoteWord(Buffer
,Section
) == true)
94 return _error
->Error(_("Malformed line %lu in source list %s (absolute dist)"),CurLine
,File
.c_str());
95 Dist
= SubstVar(Dist
,"$(ARCH)",_config
->Find("APT::Architecture"));
96 return CreateItem(List
,URI
,Dist
,Section
);
99 // Grab the rest of the dists
100 if (ParseQuoteWord(Buffer
,Section
) == false)
101 return _error
->Error(_("Malformed line %lu in source list %s (dist parse)"),CurLine
,File
.c_str());
105 if (CreateItem(List
,URI
,Dist
,Section
) == false)
108 while (ParseQuoteWord(Buffer
,Section
) == true);
114 // SourceList::pkgSourceList - Constructors /*{{{*/
115 // ---------------------------------------------------------------------
117 pkgSourceList::pkgSourceList()
121 pkgSourceList::pkgSourceList(string File
)
126 // SourceList::~pkgSourceList - Destructor /*{{{*/
127 // ---------------------------------------------------------------------
129 pkgSourceList::~pkgSourceList()
131 for (const_iterator I
= SrcList
.begin(); I
!= SrcList
.end(); I
++)
136 // SourceList::ReadMainList - Read the main source list from etc /*{{{*/
137 // ---------------------------------------------------------------------
139 bool pkgSourceList::ReadMainList()
141 // CNC:2003-03-03 - Multiple sources list support.
150 // CNC:2003-11-28 - Entries in sources.list have priority over
151 // entries in sources.list.d.
152 string Main
= _config
->FindFile("Dir::Etc::sourcelist");
153 string Parts
= _config
->FindDir("Dir::Etc::sourceparts");
155 if (FileExists(Main
) == true)
156 Res
&= ReadAppend(Main
);
157 else if (FileExists(Parts
) == false)
158 // Only warn if there are no sources.list.d.
159 _error
->WarningE("FileExists",_("Unable to read %s"),Main
.c_str());
161 if (FileExists(Parts
) == true)
162 Res
&= ReadSourceDir(Parts
);
163 else if (FileExists(Main
) == false)
164 // Only warn if there is no sources.list file.
165 _error
->WarningE("FileExists",_("Unable to read %s"),Parts
.c_str());
170 // CNC:2003-03-03 - Needed to preserve backwards compatibility.
171 // SourceList::Reset - Clear the sourcelist contents /*{{{*/
172 // ---------------------------------------------------------------------
174 void pkgSourceList::Reset()
176 for (const_iterator I
= SrcList
.begin(); I
!= SrcList
.end(); I
++)
178 SrcList
.erase(SrcList
.begin(),SrcList
.end());
181 // CNC:2003-03-03 - Function moved to ReadAppend() and Reset().
182 // SourceList::Read - Parse the sourcelist file /*{{{*/
183 // ---------------------------------------------------------------------
185 bool pkgSourceList::Read(string File
)
188 return ReadAppend(File
);
191 // SourceList::ReadAppend - Parse a sourcelist file /*{{{*/
192 // ---------------------------------------------------------------------
194 bool pkgSourceList::ReadAppend(string File
)
196 // Open the stream for reading
197 ifstream
F(File
.c_str(),ios::in
/*| ios::nocreate*/);
199 return _error
->Errno("ifstream::ifstream",_("Opening %s"),File
.c_str());
201 #if 0 // Now Reset() does this.
202 for (const_iterator I
= SrcList
.begin(); I
!= SrcList
.end(); I
++)
204 SrcList
.erase(SrcList
.begin(),SrcList
.end());
206 // CNC:2003-12-10 - 300 is too short.
210 while (F
.eof() == false)
212 F
.getline(Buffer
,sizeof(Buffer
));
214 _strtabexpand(Buffer
,sizeof(Buffer
));
215 if (F
.fail() && !F
.eof())
216 return _error
->Error(_("Line %u too long in source list %s."),
217 CurLine
,File
.c_str());
221 // CNC:2003-02-20 - Do not break if '#' is inside [].
222 for (I
= Buffer
; *I
!= 0 && *I
!= '#'; I
++)
224 for (I
++; *I
!= 0 && *I
!= ']'; I
++);
227 const char *C
= _strstrip(Buffer
);
230 if (C
[0] == '#' || C
[0] == 0)
235 if (ParseQuoteWord(C
,LineType
) == false)
236 return _error
->Error(_("Malformed line %u in source list %s (type)"),CurLine
,File
.c_str());
238 Type
*Parse
= Type::GetType(LineType
.c_str());
240 return _error
->Error(_("Type '%s' is not known on line %u in source list %s"),LineType
.c_str(),CurLine
,File
.c_str());
242 // Vendor name specified
247 if (ParseQuoteWord(C
,VendorID
) == false)
248 return _error
->Error(_("Malformed line %u in source list %s (vendor id)"),CurLine
,File
.c_str());
250 if (VendorID
.length() < 2 || VendorID
.end()[-1] != ']')
251 return _error
->Error(_("Malformed line %u in source list %s (vendor id)"),CurLine
,File
.c_str());
252 VendorID
= string(VendorID
,1,VendorID
.size()-2);
254 // for (vector<const Vendor *>::const_iterator iter = VendorList.begin();
255 // iter != VendorList.end(); iter++)
257 // if ((*iter)->GetVendorID() == VendorID)
259 // if (_config->FindB("Debug::sourceList", false))
260 // std::cerr << "Comparing VendorID \"" << VendorID << "\" with \"" << (*iter)->GetVendorID() << '"' << std::endl;
266 // if (Verifier == 0)
267 // return _error->Error(_("Unknown vendor ID '%s' in line %u of source list %s"),
268 // VendorID.c_str(),CurLine,File.c_str());
271 if (Parse
->ParseLine(SrcList
,C
,CurLine
,File
) == false)
277 // SourceList::FindIndex - Get the index associated with a file /*{{{*/
278 // ---------------------------------------------------------------------
280 bool pkgSourceList::FindIndex(pkgCache::PkgFileIterator File
,
281 pkgIndexFile
*&Found
) const
283 for (const_iterator I
= SrcList
.begin(); I
!= SrcList
.end(); I
++)
285 vector
<pkgIndexFile
*> *Indexes
= (*I
)->GetIndexFiles();
286 for (vector
<pkgIndexFile
*>::const_iterator J
= Indexes
->begin();
287 J
!= Indexes
->end(); J
++)
289 if ((*J
)->FindInCache(*File
.Cache()) == File
)
300 // SourceList::GetIndexes - Load the index files into the downloader /*{{{*/
301 // ---------------------------------------------------------------------
303 bool pkgSourceList::GetIndexes(pkgAcquire
*Owner
, bool GetAll
) const
305 for (const_iterator I
= SrcList
.begin(); I
!= SrcList
.end(); I
++)
306 if ((*I
)->GetIndexes(Owner
,GetAll
) == false)
311 // CNC:2003-03-03 - By Anton V. Denisov <avd@altlinux.org>.
312 // SourceList::ReadSourceDir - Read a directory with sources files
313 // Based on ReadConfigDir() /*{{{*/
314 // ---------------------------------------------------------------------
316 bool pkgSourceList::ReadSourceDir(string Dir
)
318 vector
<string
> const List
= GetListOfFilesInDir(Dir
, "list", true);
321 for (vector
<string
>::const_iterator I
= List
.begin(); I
!= List
.end(); I
++)
322 if (ReadAppend(*I
) == false)