From 8c23db5ce0973396f179ccec8cacdf304525dcdc Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 2 Dec 2013 08:01:00 +0100 Subject: first version with test --- apt-pkg/sourcelist.cc | 46 +++++++++++++++++++++++++++----- test/integration/test-apt-sources-deb822 | 45 +++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 6 deletions(-) create mode 100755 test/integration/test-apt-sources-deb822 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 #include #include +#include #include @@ -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 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 -- cgit v1.2.3 From ab2071eba830a092c5d5a0dd33ad94b4a9476109 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 2 Dec 2013 08:21:49 +0100 Subject: add unittest for new sourceslist parser as well --- test/libapt/makefile | 6 +++++ test/libapt/sourcelist_test.cc | 52 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 test/libapt/sourcelist_test.cc diff --git a/test/libapt/makefile b/test/libapt/makefile index 73403b24c..a8e053d6e 100644 --- a/test/libapt/makefile +++ b/test/libapt/makefile @@ -111,3 +111,9 @@ SLIBS = -lapt-pkg SOURCE = tagfile_test.cc include $(PROGRAM_H) +# test sourcelist +PROGRAM = SourceList${BASENAME} +SLIBS = -lapt-pkg +SOURCE = sourcelist_test.cc +include $(PROGRAM_H) + diff --git a/test/libapt/sourcelist_test.cc b/test/libapt/sourcelist_test.cc new file mode 100644 index 000000000..6e83d08e0 --- /dev/null +++ b/test/libapt/sourcelist_test.cc @@ -0,0 +1,52 @@ +#include +#include + +#include "assert.h" +#include +#include +#include + +char *tempfile = NULL; +int tempfile_fd = -1; + +void remove_tmpfile(void) +{ + if (tempfile_fd > 0) + close(tempfile_fd); + if (tempfile != NULL) { + unlink(tempfile); + free(tempfile); + } +} + +int main(int argc, char *argv[]) +{ + const char contents[] = "" + "Type: deb\n" + "URL: http://ftp.debian.org/debian\n" + "Dist: stable\n" + "Section: main\n" + "Comment: Some random string\n" + " that can be very long\n" + "\n" + "Type: deb\n" + "URL: http://ftp.debian.org/debian\n" + "Dist: unstable\n" + "Section: main non-free\n" + ; + + FileFd fd; + tempfile = strdup("apt-test.XXXXXXXX"); + tempfile_fd = mkstemp(tempfile); + + /* (Re-)Open (as FileFd), write and seek to start of the temp file */ + equals(fd.OpenDescriptor(tempfile_fd, FileFd::ReadWrite), true); + equals(fd.Write(contents, strlen(contents)), true); + equals(fd.Seek(0), true); + + pkgSourceList sources(tempfile); + equals(sources.size(), 2); + + /* clean up handled by atexit handler, so just return here */ + return 0; +} -- cgit v1.2.3 From 41c24955e8aa1303071348d77f661742270d05c0 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 2 Dec 2013 08:36:10 +0100 Subject: fix section adding --- apt-pkg/sourcelist.cc | 11 ++++++++++- test/integration/test-apt-sources-deb822 | 10 ++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/apt-pkg/sourcelist.cc b/apt-pkg/sourcelist.cc index 1261ebb52..4883e2fab 100644 --- a/apt-pkg/sourcelist.cc +++ b/apt-pkg/sourcelist.cc @@ -273,7 +273,16 @@ bool pkgSourceList::ReadAppend(string File) 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); + + // now create one item per section + std::vector list; + if (Section.find(",")) + list = StringSplit(Section, ","); + else + list = StringSplit(Section, " "); + for (int i=0; i < list.size(); i++) + Parse->CreateItem(SrcList, URI, Dist, list[i], Options); + i++; } // we are done diff --git a/test/integration/test-apt-sources-deb822 b/test/integration/test-apt-sources-deb822 index cdf30c02a..6e9700bb0 100755 --- a/test/integration/test-apt-sources-deb822 +++ b/test/integration/test-apt-sources-deb822 @@ -22,6 +22,16 @@ testequal "'http://ftp.debian.org/debian/dists/stable/main/binary-i386/Packages. 'http://ftp.debian.org/debian/dists/stable/InRelease' ftp.debian.org_debian_dists_stable_InRelease 0 " aptget update --print-uris +# two sections (we support both "," and " " as seperator) +echo "$BASE" | sed s/main/"main,contrib"/ > 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/contrib/binary-i386/Packages.bz2' ftp.debian.org_debian_dists_stable_contrib_binary-i386_Packages 0 : +'http://ftp.debian.org/debian/dists/stable/contrib/i18n/Translation-en.bz2' ftp.debian.org_debian_dists_stable_contrib_i18n_Translation-en 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 -- cgit v1.2.3 From a537ce19f955f39ee62281bb12bc71a4c67bc635 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 2 Dec 2013 08:01:00 +0100 Subject: first version with test --- apt-pkg/sourcelist.cc | 46 +++++++++++++++++++++++++++----- test/integration/test-apt-sources-deb822 | 45 +++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 6 deletions(-) create mode 100755 test/integration/test-apt-sources-deb822 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 #include #include +#include #include @@ -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 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 -- cgit v1.2.3 From caeb19b796f7045f489dbce0bf681925d49136a9 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 2 Dec 2013 08:21:49 +0100 Subject: add unittest for new sourceslist parser as well --- test/libapt/makefile | 6 +++++ test/libapt/sourcelist_test.cc | 52 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 test/libapt/sourcelist_test.cc diff --git a/test/libapt/makefile b/test/libapt/makefile index 73403b24c..a8e053d6e 100644 --- a/test/libapt/makefile +++ b/test/libapt/makefile @@ -111,3 +111,9 @@ SLIBS = -lapt-pkg SOURCE = tagfile_test.cc include $(PROGRAM_H) +# test sourcelist +PROGRAM = SourceList${BASENAME} +SLIBS = -lapt-pkg +SOURCE = sourcelist_test.cc +include $(PROGRAM_H) + diff --git a/test/libapt/sourcelist_test.cc b/test/libapt/sourcelist_test.cc new file mode 100644 index 000000000..6e83d08e0 --- /dev/null +++ b/test/libapt/sourcelist_test.cc @@ -0,0 +1,52 @@ +#include +#include + +#include "assert.h" +#include +#include +#include + +char *tempfile = NULL; +int tempfile_fd = -1; + +void remove_tmpfile(void) +{ + if (tempfile_fd > 0) + close(tempfile_fd); + if (tempfile != NULL) { + unlink(tempfile); + free(tempfile); + } +} + +int main(int argc, char *argv[]) +{ + const char contents[] = "" + "Type: deb\n" + "URL: http://ftp.debian.org/debian\n" + "Dist: stable\n" + "Section: main\n" + "Comment: Some random string\n" + " that can be very long\n" + "\n" + "Type: deb\n" + "URL: http://ftp.debian.org/debian\n" + "Dist: unstable\n" + "Section: main non-free\n" + ; + + FileFd fd; + tempfile = strdup("apt-test.XXXXXXXX"); + tempfile_fd = mkstemp(tempfile); + + /* (Re-)Open (as FileFd), write and seek to start of the temp file */ + equals(fd.OpenDescriptor(tempfile_fd, FileFd::ReadWrite), true); + equals(fd.Write(contents, strlen(contents)), true); + equals(fd.Seek(0), true); + + pkgSourceList sources(tempfile); + equals(sources.size(), 2); + + /* clean up handled by atexit handler, so just return here */ + return 0; +} -- cgit v1.2.3 From 300b15e3456aff88b3016a8bac90a0ba8911db8f Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 2 Dec 2013 08:36:10 +0100 Subject: fix section adding --- apt-pkg/sourcelist.cc | 11 ++++++++++- test/integration/test-apt-sources-deb822 | 10 ++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/apt-pkg/sourcelist.cc b/apt-pkg/sourcelist.cc index 1261ebb52..4883e2fab 100644 --- a/apt-pkg/sourcelist.cc +++ b/apt-pkg/sourcelist.cc @@ -273,7 +273,16 @@ bool pkgSourceList::ReadAppend(string File) 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); + + // now create one item per section + std::vector list; + if (Section.find(",")) + list = StringSplit(Section, ","); + else + list = StringSplit(Section, " "); + for (int i=0; i < list.size(); i++) + Parse->CreateItem(SrcList, URI, Dist, list[i], Options); + i++; } // we are done diff --git a/test/integration/test-apt-sources-deb822 b/test/integration/test-apt-sources-deb822 index cdf30c02a..6e9700bb0 100755 --- a/test/integration/test-apt-sources-deb822 +++ b/test/integration/test-apt-sources-deb822 @@ -22,6 +22,16 @@ testequal "'http://ftp.debian.org/debian/dists/stable/main/binary-i386/Packages. 'http://ftp.debian.org/debian/dists/stable/InRelease' ftp.debian.org_debian_dists_stable_InRelease 0 " aptget update --print-uris +# two sections (we support both "," and " " as seperator) +echo "$BASE" | sed s/main/"main,contrib"/ > 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/contrib/binary-i386/Packages.bz2' ftp.debian.org_debian_dists_stable_contrib_binary-i386_Packages 0 : +'http://ftp.debian.org/debian/dists/stable/contrib/i18n/Translation-en.bz2' ftp.debian.org_debian_dists_stable_contrib_i18n_Translation-en 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 -- cgit v1.2.3 From 6f4478134e13070517c00960e7eb3793d142c0ea Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 9 Dec 2013 07:59:18 +0100 Subject: refactor deb822 reading into its own function --- apt-pkg/sourcelist.cc | 49 +++++++++++++++++++++++++++++++++---------------- apt-pkg/sourcelist.h | 5 ++++- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/apt-pkg/sourcelist.cc b/apt-pkg/sourcelist.cc index 4883e2fab..c28cf0127 100644 --- a/apt-pkg/sourcelist.cc +++ b/apt-pkg/sourcelist.cc @@ -238,21 +238,15 @@ bool pkgSourceList::Read(string File) return ReadAppend(File); } /*}}}*/ -// SourceList::ReadAppend - Parse a sourcelist file /*{{{*/ -// --------------------------------------------------------------------- -/* */ -bool pkgSourceList::ReadAppend(string File) + +// FIXME: move into pkgSourceList::Type::ParseFile() +bool pkgSourceList::ParseFileDeb822(FileFd &Fd) { - // 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 Options; - int i=0; + unsigned int i=0; + + pkgTagFile Sources(&Fd); while (Sources.Step(Tags) == true) { if(!Tags.Exists("Type")) @@ -260,11 +254,11 @@ bool pkgSourceList::ReadAppend(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,File.c_str()); + return _error->Error(_("Type '%s' is not known on stanza %u in source list %s"),type.c_str(),i,Fd.Name().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()); + return _error->Error(_("Malformed stanza %u in source list %s (URI parse)"),i,Fd.Name().c_str()); string const Dist = Tags.FindS("Dist"); string const Section = Tags.FindS("Section"); // check if there are any options we support @@ -280,16 +274,39 @@ bool pkgSourceList::ReadAppend(string File) list = StringSplit(Section, ","); else list = StringSplit(Section, " "); - for (int i=0; i < list.size(); i++) - Parse->CreateItem(SrcList, URI, Dist, list[i], Options); + for (std::vector::const_iterator I = list.begin(); + I != list.end(); I++) + Parse->CreateItem(SrcList, URI, Dist, (*I), Options); i++; } + // we are done if(i>0) return true; + + return false; +} + + +// SourceList::ReadAppend - Parse a sourcelist file /*{{{*/ +// --------------------------------------------------------------------- +/* */ +bool pkgSourceList::ReadAppend(string File) +{ + // *first* try reading as deb822 + // FIXME: proper error handling so that we do not error for good old-style + // sources + FileFd Fd(File, FileFd::ReadOnly); + if (_error->PendingError() == false) + { + if (ParseFileDeb822(Fd)) + return true; } + + // *then* read as old-style sources.list + // Open the stream for reading ifstream F(File.c_str(),ios::in /*| ios::nocreate*/); if (!F != 0) diff --git a/apt-pkg/sourcelist.h b/apt-pkg/sourcelist.h index 02e27101a..af3f4f5c6 100644 --- a/apt-pkg/sourcelist.h +++ b/apt-pkg/sourcelist.h @@ -75,7 +75,10 @@ class pkgSourceList protected: std::vector SrcList; - + + // FIXME: move int Type with the next ABI break + bool ParseFileDeb822(FileFd &Fd); + public: bool ReadMainList(); -- cgit v1.2.3 From 1fa78a8a3730633be662df07f7aec8f4c3dcc766 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 9 Dec 2013 08:21:53 +0100 Subject: more refactor --- apt-pkg/sourcelist.cc | 133 +++++++++++++++++++++++++------------------------- apt-pkg/sourcelist.h | 4 +- 2 files changed, 69 insertions(+), 68 deletions(-) diff --git a/apt-pkg/sourcelist.cc b/apt-pkg/sourcelist.cc index c28cf0127..714918bc1 100644 --- a/apt-pkg/sourcelist.cc +++ b/apt-pkg/sourcelist.cc @@ -160,7 +160,6 @@ bool pkgSourceList::Type::ParseLine(vector &List, return true; } /*}}}*/ - // SourceList::pkgSourceList - Constructors /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -182,7 +181,6 @@ pkgSourceList::~pkgSourceList() delete *I; } /*}}}*/ - /*}}}*/ // SourceList::ReadMainList - Read the main source list from etc /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -217,7 +215,6 @@ bool pkgSourceList::ReadMainList() return Res; } /*}}}*/ -// CNC:2003-03-03 - Needed to preserve backwards compatibility. // SourceList::Reset - Clear the sourcelist contents /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -228,7 +225,6 @@ void pkgSourceList::Reset() SrcList.erase(SrcList.begin(),SrcList.end()); } /*}}}*/ -// CNC:2003-03-03 - Function moved to ReadAppend() and Reset(). // SourceList::Read - Parse the sourcelist file /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -238,75 +234,21 @@ bool pkgSourceList::Read(string File) return ReadAppend(File); } /*}}}*/ - -// FIXME: move into pkgSourceList::Type::ParseFile() -bool pkgSourceList::ParseFileDeb822(FileFd &Fd) -{ - pkgTagSection Tags; - map Options; - unsigned int i=0; - - pkgTagFile Sources(&Fd); - 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,Fd.Name().c_str()); - - 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()); - 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]); - - // now create one item per section - std::vector list; - if (Section.find(",")) - list = StringSplit(Section, ","); - else - list = StringSplit(Section, " "); - for (std::vector::const_iterator I = list.begin(); - I != list.end(); I++) - Parse->CreateItem(SrcList, URI, Dist, (*I), Options); - - i++; - } - - // we are done - if(i>0) - return true; - - return false; -} - - // SourceList::ReadAppend - Parse a sourcelist file /*{{{*/ // --------------------------------------------------------------------- /* */ bool pkgSourceList::ReadAppend(string File) { - // *first* try reading as deb822 - // FIXME: proper error handling so that we do not error for good old-style - // sources - FileFd Fd(File, FileFd::ReadOnly); - if (_error->PendingError() == false) - { - if (ParseFileDeb822(Fd)) + if (ParseFileDeb822(File)) return true; - } - - - // *then* read as old-style sources.list + return ParseFileOldStyle(File); +} +// SourceList::ReadFileOldStyle - Read Traditional style sources.list /*{{{*/ +// --------------------------------------------------------------------- +/* */ +bool pkgSourceList::ParseFileOldStyle(string File) +{ // Open the stream for reading ifstream F(File.c_str(),ios::in /*| ios::nocreate*/); if (!F != 0) @@ -358,6 +300,65 @@ bool pkgSourceList::ReadAppend(string File) return true; } /*}}}*/ +// SourceList::ParseFileDeb822 - Parse deb822 style sources.list /*{{{*/ +// --------------------------------------------------------------------- +/* */ +bool pkgSourceList::ParseFileDeb822(string File) +{ + // FIXME: proper error handling so that we do not error for good old-style + // sources + FileFd Fd(File, FileFd::ReadOnly); + if (_error->PendingError() == true) + { + return false; + } + + pkgTagSection Tags; + map Options; + unsigned int i=0; + + pkgTagFile Sources(&Fd); + 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,Fd.Name().c_str()); + + 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()); + 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]); + + // now create one item per section + std::vector list; + if (Section.find(",")) + list = StringSplit(Section, ","); + else + list = StringSplit(Section, " "); + for (std::vector::const_iterator I = list.begin(); + I != list.end(); I++) + Parse->CreateItem(SrcList, URI, Dist, (*I), Options); + + i++; + } + + // we are done + if(i>0) + return true; + + return false; +} + /*}}}*/ // SourceList::FindIndex - Get the index associated with a file /*{{{*/ // --------------------------------------------------------------------- /* */ diff --git a/apt-pkg/sourcelist.h b/apt-pkg/sourcelist.h index af3f4f5c6..5e0d585bb 100644 --- a/apt-pkg/sourcelist.h +++ b/apt-pkg/sourcelist.h @@ -76,8 +76,8 @@ class pkgSourceList std::vector SrcList; - // FIXME: move int Type with the next ABI break - bool ParseFileDeb822(FileFd &Fd); + bool ParseFileDeb822(std::string File); + bool ParseFileOldStyle(std::string File); public: -- cgit v1.2.3 From fce9f472046344d15d4f4df281a003d837cf4177 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 9 Dec 2013 08:30:01 +0100 Subject: add APT::Sources::Use-Deb822 to allow disabling the deb822 parser --- apt-pkg/sourcelist.cc | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/apt-pkg/sourcelist.cc b/apt-pkg/sourcelist.cc index 714918bc1..0bbb2bd3f 100644 --- a/apt-pkg/sourcelist.cc +++ b/apt-pkg/sourcelist.cc @@ -239,7 +239,8 @@ bool pkgSourceList::Read(string File) /* */ bool pkgSourceList::ReadAppend(string File) { - if (ParseFileDeb822(File)) + if (_config->FindB("APT::Sources::Use-Deb822", true) == true) + if (ParseFileDeb822(File)) return true; return ParseFileOldStyle(File); } @@ -305,19 +306,23 @@ bool pkgSourceList::ParseFileOldStyle(string File) /* */ bool pkgSourceList::ParseFileDeb822(string File) { - // FIXME: proper error handling so that we do not error for good old-style - // sources + + pkgTagSection Tags; + map Options; + unsigned int i=0; + + // see if we can read the file + _error->PushToStack(); FileFd Fd(File, FileFd::ReadOnly); + pkgTagFile Sources(&Fd); if (_error->PendingError() == true) { + _error->RevertToStack(); return false; } - - pkgTagSection Tags; - map Options; - unsigned int i=0; + _error->MergeWithStack(); - pkgTagFile Sources(&Fd); + // read step by step while (Sources.Step(Tags) == true) { if(!Tags.Exists("Type")) -- cgit v1.2.3 From 42e19c826b9da6c21a6d286f31db51bc04c73d87 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 9 Dec 2013 08:33:28 +0100 Subject: suppoer $(ARCH) in deb822 sources.list as well --- apt-pkg/sourcelist.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apt-pkg/sourcelist.cc b/apt-pkg/sourcelist.cc index 0bbb2bd3f..99cdbe030 100644 --- a/apt-pkg/sourcelist.cc +++ b/apt-pkg/sourcelist.cc @@ -327,6 +327,7 @@ bool pkgSourceList::ParseFileDeb822(string File) { if(!Tags.Exists("Type")) continue; + string const type = Tags.FindS("Type"); Type *Parse = Type::GetType(type.c_str()); if (Parse == 0) @@ -335,8 +336,10 @@ bool pkgSourceList::ParseFileDeb822(string File) 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()); - string const Dist = Tags.FindS("Dist"); - string const Section = Tags.FindS("Section"); + + string Dist = Tags.FindS("Dist"); + Dist = SubstVar(Dist,"$(ARCH)",_config->Find("APT::Architecture")); + // check if there are any options we support const char* option_str[] = { "arch", "arch+", "arch-", "trusted" }; @@ -345,6 +348,7 @@ bool pkgSourceList::ParseFileDeb822(string File) Options[option_str[j]] = Tags.FindS(option_str[j]); // now create one item per section + string const Section = Tags.FindS("Section"); std::vector list; if (Section.find(",")) list = StringSplit(Section, ","); -- cgit v1.2.3 From d2d68aaf5bc2211e9c488f2603ccb4e5fd591a6d Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Sat, 4 Jan 2014 15:39:04 +0100 Subject: improve tests --- apt-pkg/sourcelist.cc | 3 ++- test/integration/framework | 13 +++++++++++-- test/integration/test-apt-sources-deb822 | 21 ++++++++++++++++----- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/apt-pkg/sourcelist.cc b/apt-pkg/sourcelist.cc index 99cdbe030..35e13b6f5 100644 --- a/apt-pkg/sourcelist.cc +++ b/apt-pkg/sourcelist.cc @@ -342,7 +342,8 @@ bool pkgSourceList::ParseFileDeb822(string File) // check if there are any options we support const char* option_str[] = { - "arch", "arch+", "arch-", "trusted" }; + "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]); diff --git a/test/integration/framework b/test/integration/framework index a28363768..6ada1e9cc 100644 --- a/test/integration/framework +++ b/test/integration/framework @@ -948,13 +948,22 @@ testempty() { test -z "$($* 2>&1)" && msgpass || msgfail } -testequal() { +testequalwithmsg() { + local MSG="$1" + shift local COMPAREFILE=$(mktemp) addtrap "rm $COMPAREFILE;" echo "$1" > $COMPAREFILE shift - msgtest "Test for equality of" "$*" + msgtest "$MSG" $* 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail +} + +testequal() { + local EXPECTED="$1" + shift + local MSG="Test for equality of $*" + testequalwithmsg "$MSG" "$EXPECTED" $* } testequalor2() { diff --git a/test/integration/test-apt-sources-deb822 b/test/integration/test-apt-sources-deb822 index 6e9700bb0..24fb1bdb0 100755 --- a/test/integration/test-apt-sources-deb822 +++ b/test/integration/test-apt-sources-deb822 @@ -7,7 +7,17 @@ TESTDIR=$(readlink -f $(dirname $0)) setupenvironment configarchitecture "i386" -BASE="Type: deb +echo "deb http://ftp.debian.org/debian stable main" > rootdir/etc/apt/sources.list +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 + + +BASE="# some comment +# that contains a : as well +#Type: meep + +Type: deb URL: http://ftp.debian.org/debian Dist: stable Section: main @@ -17,7 +27,7 @@ Comment: Some random string # 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 : +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 : 'http://ftp.debian.org/debian/dists/stable/InRelease' ftp.debian.org_debian_dists_stable_InRelease 0 " aptget update --print-uris @@ -25,7 +35,7 @@ testequal "'http://ftp.debian.org/debian/dists/stable/main/binary-i386/Packages. # two sections (we support both "," and " " as seperator) echo "$BASE" | sed s/main/"main,contrib"/ > 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 : +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 : 'http://ftp.debian.org/debian/dists/stable/contrib/i18n/Translation-en.bz2' ftp.debian.org_debian_dists_stable_contrib_i18n_Translation-en 0 : 'http://ftp.debian.org/debian/dists/stable/main/i18n/Translation-en.bz2' ftp.debian.org_debian_dists_stable_main_i18n_Translation-en 0 : @@ -37,7 +47,7 @@ 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 : +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 : '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 : @@ -49,7 +59,8 @@ testequal "'http://ftp.debian.org/debian/dists/stable/main/binary-i386/Packages. 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 : +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 + -- cgit v1.2.3 From 4194c9aee2766845618ef0431fd4803b0467aab7 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Sat, 4 Jan 2014 16:23:32 +0100 Subject: improve error message --- apt-pkg/sourcelist.cc | 34 +++++++++++++++++++++----------- apt-pkg/sourcelist.h | 2 +- test/integration/test-apt-sources-deb822 | 30 ++++++++++++++++++++-------- 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 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 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 -- cgit v1.2.3