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);
}
/*}}}*/
// 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;
if (_error->PendingError() == true)
{
_error->RevertToStack();
- return false;
+ return 0;
}
_error->MergeWithStack();
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"));
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 /*{{{*/
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
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 :
# 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 :
# 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 :
# 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