summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apt-pkg/sourcelist.cc34
-rw-r--r--apt-pkg/sourcelist.h2
-rwxr-xr-xtest/integration/test-apt-sources-deb82230
3 files changed, 45 insertions, 21 deletions
diff --git a/apt-pkg/sourcelist.cc b/apt-pkg/sourcelist.cc
index 35e13b6f5..5e4a58e95 100644
--- a/apt-pkg/sourcelist.cc
+++ b/apt-pkg/sourcelist.cc
@@ -240,8 +240,14 @@ bool pkgSourceList::Read(string File)
bool pkgSourceList::ReadAppend(string File)
{
if (_config->FindB("APT::Sources::Use-Deb822", true) == true)
- if (ParseFileDeb822(File))
+ {
+ int lines_parsed =ParseFileDeb822(File);
+ if (lines_parsed < 0)
+ return false;
+ else if (lines_parsed > 0)
return true;
+ // no lines parsed ... fall through and use old style parser
+ }
return ParseFileOldStyle(File);
}
@@ -303,10 +309,9 @@ bool pkgSourceList::ParseFileOldStyle(string File)
/*}}}*/
// SourceList::ParseFileDeb822 - Parse deb822 style sources.list /*{{{*/
// ---------------------------------------------------------------------
-/* */
-bool pkgSourceList::ParseFileDeb822(string File)
+/* Returns: the number of stanzas parsed*/
+int pkgSourceList::ParseFileDeb822(string File)
{
-
pkgTagSection Tags;
map<string, string> Options;
unsigned int i=0;
@@ -318,7 +323,7 @@ bool pkgSourceList::ParseFileDeb822(string File)
if (_error->PendingError() == true)
{
_error->RevertToStack();
- return false;
+ return 0;
}
_error->MergeWithStack();
@@ -331,11 +336,19 @@ bool pkgSourceList::ParseFileDeb822(string File)
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,Fd.Name().c_str());
+ {
+ _error->Error(_("Type '%s' is not known on stanza %u in source list %s"),type.c_str(),i,Fd.Name().c_str());
+ // true means we do not retry with old-style sources.list
+ return -1;
+ }
string URI = Tags.FindS("URL");
if (!Parse->FixupURI(URI))
- return _error->Error(_("Malformed stanza %u in source list %s (URI parse)"),i,Fd.Name().c_str());
+ {
+ _error->Error(_("Malformed stanza %u in source list %s (URI parse)"),i,Fd.Name().c_str());
+ // means we do not retry with old-style sources.list
+ return -1;
+ }
string Dist = Tags.FindS("Dist");
Dist = SubstVar(Dist,"$(ARCH)",_config->Find("APT::Architecture"));
@@ -362,11 +375,8 @@ bool pkgSourceList::ParseFileDeb822(string File)
i++;
}
- // we are done
- if(i>0)
- return true;
-
- return false;
+ // we are done, return the number of stanzas read
+ return i;
}
/*}}}*/
// SourceList::FindIndex - Get the index associated with a file /*{{{*/
diff --git a/apt-pkg/sourcelist.h b/apt-pkg/sourcelist.h
index 5e0d585bb..d83c76d6a 100644
--- a/apt-pkg/sourcelist.h
+++ b/apt-pkg/sourcelist.h
@@ -76,7 +76,7 @@ class pkgSourceList
std::vector<metaIndex *> SrcList;
- bool ParseFileDeb822(std::string File);
+ int ParseFileDeb822(std::string File);
bool ParseFileOldStyle(std::string File);
public:
diff --git a/test/integration/test-apt-sources-deb822 b/test/integration/test-apt-sources-deb822
index 24fb1bdb0..bacad1ed4 100755
--- a/test/integration/test-apt-sources-deb822
+++ b/test/integration/test-apt-sources-deb822
@@ -7,7 +7,9 @@ TESTDIR=$(readlink -f $(dirname $0))
setupenvironment
configarchitecture "i386"
-echo "deb http://ftp.debian.org/debian stable main" > rootdir/etc/apt/sources.list
+SOURCES="rootdir/etc/apt/sources.list"
+
+echo "deb http://ftp.debian.org/debian stable main" > $SOURCES
testequalwithmsg "Old style sources.list works" "'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
@@ -25,7 +27,7 @@ Comment: Some random string
that can be very long"
# simple case
-echo "$BASE" > rootdir/etc/apt/sources.list
+echo "$BASE" > $SOURCES
testequalwithmsg "Simple deb822 sources.list works" "'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 :
@@ -33,7 +35,7 @@ testequalwithmsg "Simple deb822 sources.list works" "'http://ftp.debian.org/debi
# two sections (we support both "," and " " as seperator)
-echo "$BASE" | sed s/main/"main,contrib"/ > rootdir/etc/apt/sources.list
+echo "$BASE" | sed s/main/"main,contrib"/ > $SOURCES
testequalwithmsg "Two sections deb822 sources.list work" "'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/contrib/binary-i386/Packages.bz2' ftp.debian.org_debian_dists_stable_contrib_binary-i386_Packages 0 :
@@ -43,9 +45,9 @@ testequalwithmsg "Two sections deb822 sources.list work" "'http://ftp.debian.org
# 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
+echo "$BASE" > $SOURCES
+echo "" >> $SOURCES
+echo "$BASE" | sed s/stable/unstable/ >> $SOURCES
testequalwithmsg "Multiple entries in deb822 sources.list work" "'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 :
@@ -56,11 +58,23 @@ testequalwithmsg "Multiple entries in deb822 sources.list work" "'http://ftp.deb
# ARCH option
-echo "$BASE" > rootdir/etc/apt/sources.list
-echo "Arch: amd64,armel" >> rootdir/etc/apt/sources.list
+echo "$BASE" > $SOURCES
+echo "Arch: amd64,armel" >> $SOURCES
testequalwithmsg "Arch: option in deb822 sources.list works" "'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
+# invalid sources.list file
+echo "deb http://ftp.debian.org" > $SOURCES
+
+testequalwithmsg "Invalid sources.list file gives proper error" "E: Malformed line 1 in source list $TMPWORKINGDIRECTORY/rootdir/etc/apt/sources.list (dist)
+E: The list of sources could not be read." aptget update --print-uris
+
+echo "Type: deb
+Dist: stable
+" > $SOURCES
+
+testequalwithmsg "Invalid deb822 sources.list file gives proper error" "E: Malformed stanza 0 in source list $TMPWORKINGDIRECTORY/rootdir/etc/apt/sources.list (URI parse)
+E: The list of sources could not be read." aptget update --print-uris