X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/b2e465d6d32d2dc884f58b94acb7e35f671a87fe..a7307a8727c85b0166339a54fb14ba3812f7a608:/apt-pkg/sourcelist.cc diff --git a/apt-pkg/sourcelist.cc b/apt-pkg/sourcelist.cc index da7e38f6e..929259961 100644 --- a/apt-pkg/sourcelist.cc +++ b/apt-pkg/sourcelist.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: sourcelist.cc,v 1.18 2001/02/20 07:03:17 jgg Exp $ +// $Id: sourcelist.cc,v 1.3 2002/08/15 20:51:37 niemeyer Exp $ /* ###################################################################### List of Sources @@ -8,22 +8,20 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ -#ifdef __GNUG__ -#pragma implementation "apt-pkg/sourcelist.h" -#endif - #include #include #include -#include #include +#include #include -#include +#include /*}}}*/ -// Global list of Item supported +using namespace std; + +// Global list of Items supported static pkgSourceList::Type *ItmList[10]; pkgSourceList::Type **pkgSourceList::Type::GlobalList = ItmList; unsigned long pkgSourceList::Type::GlobalListLen = 0; @@ -61,7 +59,7 @@ bool pkgSourceList::Type::FixupURI(string &URI) const URI = SubstVar(URI,"$(ARCH)",_config->Find("APT::Architecture")); - // Make sure that the URN is / postfixed + // Make sure that the URI is / postfixed if (URI[URI.size() - 1] != '/') URI += '/'; @@ -72,7 +70,7 @@ bool pkgSourceList::Type::FixupURI(string &URI) const // --------------------------------------------------------------------- /* This is a generic one that is the 'usual' format for sources.list Weird types may override this. */ -bool pkgSourceList::Type::ParseLine(vector &List, +bool pkgSourceList::Type::ParseLine(vector &List, const char *Buffer, unsigned long CurLine, string File) const @@ -93,7 +91,7 @@ bool pkgSourceList::Type::ParseLine(vector &List, if (Dist.empty() == false && Dist[Dist.size() - 1] == '/') { if (ParseQuoteWord(Buffer,Section) == true) - return _error->Error(_("Malformed line %lu in source list %s (Absolute dist)"),CurLine,File.c_str()); + return _error->Error(_("Malformed line %lu in source list %s (absolute dist)"),CurLine,File.c_str()); Dist = SubstVar(Dist,"$(ARCH)",_config->Find("APT::Architecture")); return CreateItem(List,URI,Dist,Section); } @@ -125,26 +123,88 @@ pkgSourceList::pkgSourceList(string File) Read(File); } /*}}}*/ +// SourceList::~pkgSourceList - Destructor /*{{{*/ +// --------------------------------------------------------------------- +/* */ +pkgSourceList::~pkgSourceList() +{ + for (const_iterator I = SrcList.begin(); I != SrcList.end(); I++) + delete *I; +} + /*}}}*/ + /*}}}*/ // SourceList::ReadMainList - Read the main source list from etc /*{{{*/ // --------------------------------------------------------------------- /* */ bool pkgSourceList::ReadMainList() { - return Read(_config->FindFile("Dir::Etc::sourcelist")); + // CNC:2003-03-03 - Multiple sources list support. + bool Res = true; +#if 0 + Res = ReadVendors(); + if (Res == false) + return false; +#endif + + Reset(); + // CNC:2003-11-28 - Entries in sources.list have priority over + // entries in sources.list.d. + string Main = _config->FindFile("Dir::Etc::sourcelist"); + string Parts = _config->FindDir("Dir::Etc::sourceparts"); + + if (FileExists(Main) == true) + Res &= ReadAppend(Main); + else if (FileExists(Parts) == false) + // Only warn if there are no sources.list.d. + _error->WarningE("FileExists",_("Unable to read %s"),Main.c_str()); + + if (FileExists(Parts) == true) + Res &= ReadSourceDir(Parts); + else if (FileExists(Main) == false) + // Only warn if there is no sources.list file. + _error->WarningE("FileExists",_("Unable to read %s"),Parts.c_str()); + + return Res; +} + /*}}}*/ +// CNC:2003-03-03 - Needed to preserve backwards compatibility. +// SourceList::Reset - Clear the sourcelist contents /*{{{*/ +// --------------------------------------------------------------------- +/* */ +void pkgSourceList::Reset() +{ + for (const_iterator I = SrcList.begin(); I != SrcList.end(); I++) + delete *I; + SrcList.erase(SrcList.begin(),SrcList.end()); } /*}}}*/ +// CNC:2003-03-03 - Function moved to ReadAppend() and Reset(). // SourceList::Read - Parse the sourcelist file /*{{{*/ // --------------------------------------------------------------------- /* */ bool pkgSourceList::Read(string File) +{ + Reset(); + return ReadAppend(File); +} + /*}}}*/ +// SourceList::ReadAppend - Parse a sourcelist file /*{{{*/ +// --------------------------------------------------------------------- +/* */ +bool pkgSourceList::ReadAppend(string File) { // Open the stream for reading - ifstream F(File.c_str(),ios::in | ios::nocreate); + ifstream F(File.c_str(),ios::in /*| ios::nocreate*/); if (!F != 0) return _error->Errno("ifstream::ifstream",_("Opening %s"),File.c_str()); - List.erase(List.begin(),List.end()); - char Buffer[300]; +#if 0 // Now Reset() does this. + for (const_iterator I = SrcList.begin(); I != SrcList.end(); I++) + delete *I; + SrcList.erase(SrcList.begin(),SrcList.end()); +#endif + // CNC:2003-12-10 - 300 is too short. + char Buffer[1024]; int CurLine = 0; while (F.eof() == false) @@ -152,10 +212,16 @@ bool pkgSourceList::Read(string File) F.getline(Buffer,sizeof(Buffer)); CurLine++; _strtabexpand(Buffer,sizeof(Buffer)); - + if (F.fail() && !F.eof()) + return _error->Error(_("Line %u too long in source list %s."), + CurLine,File.c_str()); + char *I; - for (I = Buffer; *I != 0 && *I != '#'; I++); + // CNC:2003-02-20 - Do not break if '#' is inside []. + for (I = Buffer; *I != 0 && *I != '#'; I++) + if (*I == '[') + for (I++; *I != 0 && *I != ']'; I++); *I = 0; const char *C = _strstrip(Buffer); @@ -171,9 +237,38 @@ bool pkgSourceList::Read(string File) 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()); + return _error->Error(_("Type '%s' is not known on line %u in source list %s"),LineType.c_str(),CurLine,File.c_str()); - if (Parse->ParseLine(List,C,CurLine,File) == false) + // Vendor name specified + 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()); + + 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::const_iterator iter = VendorList.begin(); +// iter != VendorList.end(); iter++) +// { +// if ((*iter)->GetVendorID() == VendorID) +// { +// if (_config->FindB("Debug::sourceList", false)) +// std::cerr << "Comparing VendorID \"" << VendorID << "\" with \"" << (*iter)->GetVendorID() << '"' << std::endl; +// Verifier = *iter; +// break; +// } +// } + +// if (Verifier == 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,C,CurLine,File) == false) return false; } return true; @@ -185,26 +280,49 @@ bool pkgSourceList::Read(string File) bool pkgSourceList::FindIndex(pkgCache::PkgFileIterator File, pkgIndexFile *&Found) const { - for (const_iterator I = List.begin(); I != List.end(); I++) + for (const_iterator I = SrcList.begin(); I != SrcList.end(); I++) { - if ((*I)->FindInCache(*File.Cache()) == File) + vector *Indexes = (*I)->GetIndexFiles(); + for (vector::const_iterator J = Indexes->begin(); + J != Indexes->end(); J++) { - Found = *I; - return true; + if ((*J)->FindInCache(*File.Cache()) == File) + { + Found = (*J); + return true; + } } } - + return false; } /*}}}*/ // SourceList::GetIndexes - Load the index files into the downloader /*{{{*/ // --------------------------------------------------------------------- /* */ -bool pkgSourceList::GetIndexes(pkgAcquire *Owner) const +bool pkgSourceList::GetIndexes(pkgAcquire *Owner, bool GetAll) const { - for (const_iterator I = List.begin(); I != List.end(); I++) - if ((*I)->GetIndexes(Owner) == false) + for (const_iterator I = SrcList.begin(); I != SrcList.end(); I++) + if ((*I)->GetIndexes(Owner,GetAll) == false) return false; return true; } /*}}}*/ +// CNC:2003-03-03 - By Anton V. Denisov . +// SourceList::ReadSourceDir - Read a directory with sources files +// Based on ReadConfigDir() /*{{{*/ +// --------------------------------------------------------------------- +/* */ +bool pkgSourceList::ReadSourceDir(string Dir) +{ + vector const List = GetListOfFilesInDir(Dir, "list", true); + + // Read the files + for (vector::const_iterator I = List.begin(); I != List.end(); I++) + if (ReadAppend(*I) == false) + return false; + return true; + +} + /*}}}*/ +