summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Vogt <mvo@debian.org>2013-12-02 08:01:00 +0100
committerMichael Vogt <mvo@debian.org>2013-12-05 15:30:56 +0100
commita537ce19f955f39ee62281bb12bc71a4c67bc635 (patch)
treeff003a7e12a9e41d89a27b35780fb03a66c030e9
parentc4b22e98645bb14d9934f1a6721c9ac8b24a68f7 (diff)
first version with test
-rw-r--r--apt-pkg/sourcelist.cc46
-rwxr-xr-xtest/integration/test-apt-sources-deb82245
2 files changed, 85 insertions, 6 deletions
diff --git a/apt-pkg/sourcelist.cc b/apt-pkg/sourcelist.cc
index 0fd237cad..1261ebb52 100644
--- a/apt-pkg/sourcelist.cc
+++ b/apt-pkg/sourcelist.cc
@@ -17,6 +17,7 @@
#include <apt-pkg/configuration.h>
#include <apt-pkg/metaindex.h>
#include <apt-pkg/indexfile.h>
+#include <apt-pkg/tagfile.h>
#include <fstream>
@@ -242,16 +243,49 @@ bool pkgSourceList::Read(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());
-
-#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];
diff --git a/test/integration/test-apt-sources-deb822 b/test/integration/test-apt-sources-deb822
new file mode 100755
index 000000000..cdf30c02a
--- /dev/null
+++ b/test/integration/test-apt-sources-deb822
@@ -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