Bug#92899: libapt-pkg: Methods for adding source entries on the fly withouthaving to understand pkgSourceList::Type
Package: apt
Version: 0.5.4
Severity: wishlist
Hi,
The attached patch splits the pkgSourceList::Read() method in two parts:
One that reads the file and one that parses the lines. This way, you can
add sources that are not listed in a sources.list file but should be
specified in the same way at some place (in my case: Added from the config
file, conditionally).
The other option would be to parse the first word myself and give the rest
of the line to the appropriate Type::ParseLine(), but that would be
duplicating code; also it will create problems if the interface changes in
the future.
The patch should apply cleanly to current CVS.
Simon
Index: apt-pkg/sourcelist.cc
===================================================================
RCS file: /cvs/deity/apt/apt-pkg/sourcelist.cc,v
retrieving revision 1.19
diff -u -r1.19 sourcelist.cc
--- apt-pkg/sourcelist.cc 2001/03/13 06:51:46 1.19
+++ apt-pkg/sourcelist.cc 2001/04/04 17:07:45
@@ -210,47 +210,60 @@
// Comment or blank
if (C[0] == '#' || C[0] == 0)
continue;
-
- // Grok it
- string LineType;
- if (ParseQuoteWord(C,LineType) == false)
- return _error->Error(_("Malformed line %u in source list %s (type)"),CurLine,File.c_str());
-
- Type *Parse = Type::GetType(LineType.c_str());
- if (Parse == 0)
- return _error->Error(_("Type '%s' is not known in on line %u in source list %s"),LineType.c_str(),CurLine,File.c_str());
+
+ if (Add(C, File, CurLine) == false)
+ return false;
+ }
+ return true;
+}
+ /*}}}*/
+// SourceList::Add() - Add an entry to the source list /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool pkgSourceList::Add(const string &Source, const string &File, int CurLine) {
+ return Add(Source.c_str(), File, CurLine);
+}
+
+bool pkgSourceList::Add(const char *Source, const string &File, int CurLine) {
+ // Grok it
+ string LineType;
+ if (ParseQuoteWord(Source,LineType) == false)
+ return _error->Error(_("Malformed line %u in source list %s (type)"),CurLine,File.c_str());
+
+ Type *Parse = Type::GetType(LineType.c_str());
+ if (Parse == 0)
+ return _error->Error(_("Type '%s' is not known in on line %u in source list %s"),LineType.c_str(),CurLine,File.c_str());
- // Authenticated repository
- Vendor const *Vndr = 0;
- if (C[0] == '[')
- {
- string VendorID;
-
- if (ParseQuoteWord(C,VendorID) == false)
- return _error->Error(_("Malformed line %u in source list %s (vendor id)"),CurLine,File.c_str());
+ // Authenticated repository
+ Vendor const *Vndr = 0;
+ if (Source[0] == '[')
+ {
+ string VendorID;
- if (VendorID.length() < 2 || VendorID.end()[-1] != ']')
- return _error->Error(_("Malformed line %u in source list %s (vendor id)"),CurLine,File.c_str());
- VendorID = string(VendorID,1,VendorID.size()-2);
+ if (ParseQuoteWord(Source,VendorID) == false)
+ return _error->Error(_("Malformed line %u in source list %s (vendor id)"),CurLine,File.c_str());
+
+ if (VendorID.length() < 2 || VendorID.end()[-1] != ']')
+ return _error->Error(_("Malformed line %u in source list %s (vendor id)"),CurLine,File.c_str());
+ VendorID = string(VendorID,1,VendorID.size()-2);
- for (vector<Vendor const *>::const_iterator iter = VendorList.begin();
- iter != VendorList.end(); iter++)
+ for (vector<Vendor const *>::const_iterator iter = VendorList.begin();
+ iter != VendorList.end(); iter++)
+ {
+ if ((*iter)->VendorID == VendorID)
{
- if ((*iter)->VendorID == VendorID)
- {
- Vndr = *iter;
- break;
- }
+ Vndr = *iter;
+ break;
}
-
- if (Vndr == 0)
- return _error->Error(_("Unknown vendor ID '%s' in line %u of source list %s"),
- VendorID.c_str(),CurLine,File.c_str());
}
-
- if (Parse->ParseLine(SrcList,Vndr,C,CurLine,File) == false)
- return false;
+
+ if (Vndr == 0)
+ return _error->Error(_("Unknown vendor ID '%s' in line %u of source list %s"),
+ VendorID.c_str(),CurLine,File.c_str());
}
+
+ if (Parse->ParseLine(SrcList,Vndr,Source,CurLine,File) == false)
+ return false;
return true;
}
/*}}}*/
Index: apt-pkg/sourcelist.h
===================================================================
RCS file: /cvs/deity/apt/apt-pkg/sourcelist.h,v
retrieving revision 1.10
diff -u -r1.10 sourcelist.h
--- apt-pkg/sourcelist.h 2001/03/13 06:51:46 1.10
+++ apt-pkg/sourcelist.h 2001/04/04 17:07:45
@@ -90,6 +90,8 @@
bool ReadMainList();
bool Read(string File);
+ bool Add(const string &Source, const string &File, int CurLine);
+ bool Add(const char *Source, const string &File, int CurLine);
bool ReadVendors();
// List accessors
--
GPG public key available from http://phobos.fs.tum.de/pgp/Simon.Richter.asc
Fingerprint: DC26 EB8D 1F35 4F44 2934 7583 DBB6 F98D 9198 3292
Hi! I'm a .signature virus! Copy me into your ~/.signature to help me spread!
Reply to: