]> git.saurik.com Git - apt.git/commitdiff
first version with test
authorMichael Vogt <mvo@debian.org>
Mon, 2 Dec 2013 07:01:00 +0000 (08:01 +0100)
committerMichael Vogt <mvo@debian.org>
Thu, 5 Dec 2013 14:30:56 +0000 (15:30 +0100)
apt-pkg/sourcelist.cc
test/integration/test-apt-sources-deb822 [new file with mode: 0755]

index 0fd237cadaffe91ffeed735d2169e2b76a1aef18..1261ebb5244d515415c153d046576e7f8d319098 100644 (file)
@@ -17,6 +17,7 @@
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/metaindex.h>
 #include <apt-pkg/indexfile.h>
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/metaindex.h>
 #include <apt-pkg/indexfile.h>
+#include <apt-pkg/tagfile.h>
 
 #include <fstream>
 
 
 #include <fstream>
 
@@ -242,16 +243,49 @@ bool pkgSourceList::Read(string File)
 /* */
 bool pkgSourceList::ReadAppend(string File)
 {
 /* */
 bool pkgSourceList::ReadAppend(string File)
 {
+   // try reading as deb822
+   // FIXME: proper error handling so that we do not error for good old-style
+   //        sources
+   FileFd Fd(File, FileFd::ReadOnly);
+   pkgTagFile Sources(&Fd);
+   if (_error->PendingError() == false)
+   {
+      pkgTagSection Tags;
+      map<string, string> Options;
+      int i=0;
+      while (Sources.Step(Tags) == true)
+      {
+         if(!Tags.Exists("Type")) 
+            continue;
+         string const type = Tags.FindS("Type");
+         Type *Parse = Type::GetType(type.c_str());
+         if (Parse == 0)
+            return _error->Error(_("Type '%s' is not known on stanza %u in source list %s"),type.c_str(),i,File.c_str());
+         
+         string URI = Tags.FindS("URL");
+         if (!Parse->FixupURI(URI))
+            return _error->Error(_("Malformed stanza %lu in source list %s (URI parse)"),i,File.c_str());
+         string const Dist = Tags.FindS("Dist");
+         string const Section = Tags.FindS("Section");
+         // check if there are any options we support
+         const char* option_str[] = { 
+            "arch", "arch+", "arch-", "trusted" };
+         for (unsigned int j=0; j < sizeof(option_str)/sizeof(char*); j++)
+            if (Tags.Exists(option_str[j]))
+               Options[option_str[j]] = Tags.FindS(option_str[j]);
+         Parse->CreateItem(SrcList, URI, Dist, Section, Options);
+         i++;
+      }
+      // we are done
+      if(i>0)
+         return true;
+   }
+
    // 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());
    // 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());
-#endif
+
    // CNC:2003-12-10 - 300 is too short.
    char Buffer[1024];
 
    // CNC:2003-12-10 - 300 is too short.
    char Buffer[1024];
 
diff --git a/test/integration/test-apt-sources-deb822 b/test/integration/test-apt-sources-deb822
new file mode 100755 (executable)
index 0000000..cdf30c0
--- /dev/null
@@ -0,0 +1,45 @@
+#!/bin/sh
+set -e
+
+TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+
+setupenvironment
+configarchitecture "i386"
+
+BASE="Type: deb
+URL: http://ftp.debian.org/debian
+Dist: stable
+Section: main
+Comment: Some random string
+ that can be very long"
+
+# simple case
+echo "$BASE" > rootdir/etc/apt/sources.list
+
+testequal "'http://ftp.debian.org/debian/dists/stable/main/binary-i386/Packages.bz2' ftp.debian.org_debian_dists_stable_main_binary-i386_Packages 0 :
+'http://ftp.debian.org/debian/dists/stable/main/i18n/Translation-en.bz2' ftp.debian.org_debian_dists_stable_main_i18n_Translation-en 0 :
+'http://ftp.debian.org/debian/dists/stable/InRelease' ftp.debian.org_debian_dists_stable_InRelease 0 "  aptget update --print-uris 
+
+
+# Two entries
+echo "$BASE" > rootdir/etc/apt/sources.list
+echo "" >> rootdir/etc/apt/sources.list
+echo "$BASE" | sed  s/stable/unstable/ >> rootdir/etc/apt/sources.list
+
+testequal "'http://ftp.debian.org/debian/dists/stable/main/binary-i386/Packages.bz2' ftp.debian.org_debian_dists_stable_main_binary-i386_Packages 0 :
+'http://ftp.debian.org/debian/dists/stable/main/i18n/Translation-en.bz2' ftp.debian.org_debian_dists_stable_main_i18n_Translation-en 0 :
+'http://ftp.debian.org/debian/dists/stable/InRelease' ftp.debian.org_debian_dists_stable_InRelease 0 
+'http://ftp.debian.org/debian/dists/unstable/main/binary-i386/Packages.bz2' ftp.debian.org_debian_dists_unstable_main_binary-i386_Packages 0 :
+'http://ftp.debian.org/debian/dists/unstable/main/i18n/Translation-en.bz2' ftp.debian.org_debian_dists_unstable_main_i18n_Translation-en 0 :
+'http://ftp.debian.org/debian/dists/unstable/InRelease' ftp.debian.org_debian_dists_unstable_InRelease 0 "  aptget update --print-uris 
+
+
+# ARCH option
+echo "$BASE" > rootdir/etc/apt/sources.list
+echo "Arch: amd64,armel" >> rootdir/etc/apt/sources.list
+
+testequal "'http://ftp.debian.org/debian/dists/stable/main/binary-amd64/Packages.bz2' ftp.debian.org_debian_dists_stable_main_binary-amd64_Packages 0 :
+'http://ftp.debian.org/debian/dists/stable/main/binary-armel/Packages.bz2' ftp.debian.org_debian_dists_stable_main_binary-armel_Packages 0 :
+'http://ftp.debian.org/debian/dists/stable/main/i18n/Translation-en.bz2' ftp.debian.org_debian_dists_stable_main_i18n_Translation-en 0 :
+'http://ftp.debian.org/debian/dists/stable/InRelease' ftp.debian.org_debian_dists_stable_InRelease 0 "  aptget update --print-uris