]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/sourcelist.cc
methods/gzip.cc: With FileFd now being able to read gzipped files, there
[apt.git] / apt-pkg / sourcelist.cc
index 95aba0cb58d3de643cb4cda4a99c0d8f44c088e2..929259961e966a74b5cb404ecfca57ff67d39c3c 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: sourcelist.cc,v 1.25 2004/06/07 23:08:00 mdz Exp $
+// $Id: sourcelist.cc,v 1.3 2002/08/15 20:51:37 niemeyer Exp $
 /* ######################################################################
 
    List of Sources
@@ -8,10 +8,6 @@
    ##################################################################### */
                                                                        /*}}}*/
 // Include Files                                                       /*{{{*/
-#ifdef __GNUG__
-#pragma implementation "apt-pkg/sourcelist.h"
-#endif
-
 #include <apt-pkg/sourcelist.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/fileutl.h>
@@ -142,23 +138,73 @@ pkgSourceList::~pkgSourceList()
 /* */
 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*/);
    if (!F != 0)
       return _error->Errno("ifstream::ifstream",_("Opening %s"),File.c_str());
    
+#if 0 // Now Reset() does this.
    for (const_iterator I = SrcList.begin(); I != SrcList.end(); I++)
       delete *I;
    SrcList.erase(SrcList.begin(),SrcList.end());
-   char Buffer[300];
+#endif
+   // CNC:2003-12-10 - 300 is too short.
+   char Buffer[1024];
 
    int CurLine = 0;
    while (F.eof() == false)
@@ -172,7 +218,10 @@ bool pkgSourceList::Read(string File)
 
       
       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);
@@ -259,3 +308,21 @@ bool pkgSourceList::GetIndexes(pkgAcquire *Owner, bool GetAll) const
    return true;
 }
                                                                        /*}}}*/
+// CNC:2003-03-03 - By Anton V. Denisov <avd@altlinux.org>.
+// SourceList::ReadSourceDir - Read a directory with sources files
+// Based on ReadConfigDir()                                            /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool pkgSourceList::ReadSourceDir(string Dir)
+{
+   vector<string> const List = GetListOfFilesInDir(Dir, "list", true);
+
+   // Read the files
+   for (vector<string>::const_iterator I = List.begin(); I != List.end(); I++)
+      if (ReadAppend(*I) == false)
+        return false;
+   return true;
+
+}
+                                                                       /*}}}*/
+