From 8628c2f7a6a8769a6250280d62791a8429aa71ba Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 2 Sep 2012 21:32:40 +0200 Subject: [PATCH] * apt-pkg/cdrom.cc: - handle Components in the reduction for the source.list as multi-arch cds otherwise create duplicated source entries (e.g. "wheezy main main") --- apt-pkg/cdrom.cc | 9 ++- debian/changelog | 3 + test/libapt/cdromreducesourcelist_test.cc | 86 +++++++++++++++++++++++ test/libapt/makefile | 6 ++ 4 files changed, 101 insertions(+), 3 deletions(-) create mode 100644 test/libapt/cdromreducesourcelist_test.cc diff --git a/apt-pkg/cdrom.cc b/apt-pkg/cdrom.cc index 699f66fb..8e746ee3 100644 --- a/apt-pkg/cdrom.cc +++ b/apt-pkg/cdrom.cc @@ -363,6 +363,7 @@ void pkgCdrom::ReduceSourcelist(string CD,vector &List) string Word1 = string(*I,Space,SSpace-Space); string Prefix = string(*I,0,Space); + string Component = string(*I,SSpace); for (vector::iterator J = List.begin(); J != I; ++J) { // Find a space.. @@ -377,9 +378,11 @@ void pkgCdrom::ReduceSourcelist(string CD,vector &List) continue; if (string(*J,Space2,SSpace2-Space2) != Word1) continue; - - *J += string(*I,SSpace); - *I = string(); + + string Component2 = string(*J, SSpace2) + " "; + if (Component2.find(Component + " ") == std::string::npos) + *J += Component; + I->clear(); } } diff --git a/debian/changelog b/debian/changelog index 4533d27e..703764de 100644 --- a/debian/changelog +++ b/debian/changelog @@ -18,6 +18,9 @@ apt (0.9.7.5) UNRELEASED; urgency=low * apt-pkg/indexcopy.cc: - do not create duplicated flat-archive cdrom sources for foreign architectures on multi-arch cdroms + * apt-pkg/cdrom.cc: + - handle Components in the reduction for the source.list as multi-arch cds + otherwise create duplicated source entries (e.g. "wheezy main main") -- David Kalnischkies Sun, 26 Aug 2012 10:49:17 +0200 diff --git a/test/libapt/cdromreducesourcelist_test.cc b/test/libapt/cdromreducesourcelist_test.cc new file mode 100644 index 00000000..729da23a --- /dev/null +++ b/test/libapt/cdromreducesourcelist_test.cc @@ -0,0 +1,86 @@ +#include +#include + +#include +#include +#include + +#include "assert.h" + +class Cdrom : public pkgCdrom { +public: + std::vector ReduceSourcelist(std::string CD,std::vector List) { + pkgCdrom::ReduceSourcelist(CD, List); + return List; + } +}; + +int main(int argc, char const *argv[]) { + Cdrom cd; + std::vector List; + std::string CD("/media/cdrom/"); + + std::vector R = cd.ReduceSourcelist(CD, List); + equals(R.empty(), true); + + List.push_back(" wheezy main"); + R = cd.ReduceSourcelist(CD, List); + equals(R.size(), 1); + equals(R[0], " wheezy main"); + + List.push_back(" wheezy main"); + R = cd.ReduceSourcelist(CD, List); + equals(R.size(), 1); + equals(R[0], " wheezy main"); + + List.push_back(" wheezy contrib"); + R = cd.ReduceSourcelist(CD, List); + equals(R.size(), 1); + equals(R[0], " wheezy contrib main"); + + List.push_back(" wheezy-update contrib"); + R = cd.ReduceSourcelist(CD, List); + equals(R.size(), 2); + equals(R[0], " wheezy contrib main"); + equals(R[1], " wheezy-update contrib"); + + List.push_back(" wheezy-update contrib"); + R = cd.ReduceSourcelist(CD, List); + equals(R.size(), 2); + equals(R[0], " wheezy contrib main"); + equals(R[1], " wheezy-update contrib"); + + List.push_back(" wheezy-update non-free"); + R = cd.ReduceSourcelist(CD, List); + equals(R.size(), 2); + equals(R[0], " wheezy contrib main"); + equals(R[1], " wheezy-update contrib non-free"); + + List.push_back(" wheezy-update main"); + R = cd.ReduceSourcelist(CD, List); + equals(R.size(), 2); + equals(R[0], " wheezy contrib main"); + equals(R[1], " wheezy-update contrib main non-free"); + + List.push_back(" wheezy non-free"); + R = cd.ReduceSourcelist(CD, List); + equals(R.size(), 2); + equals(R[0], " wheezy contrib main non-free"); + equals(R[1], " wheezy-update contrib main non-free"); + + List.push_back(" sid main"); + R = cd.ReduceSourcelist(CD, List); + equals(R.size(), 3); + equals(R[0], " sid main"); + equals(R[1], " wheezy contrib main non-free"); + equals(R[2], " wheezy-update contrib main non-free"); + + List.push_back(" sid main-reduce"); + R = cd.ReduceSourcelist(CD, List); + equals(R.size(), 3); + equals(R[0], " sid main main-reduce"); + equals(R[1], " wheezy contrib main non-free"); + equals(R[2], " wheezy-update contrib main non-free"); + + return 0; +} diff --git a/test/libapt/makefile b/test/libapt/makefile index d4d7f175..5e225f24 100644 --- a/test/libapt/makefile +++ b/test/libapt/makefile @@ -87,6 +87,12 @@ SLIBS = -lapt-pkg SOURCE = cdromfindpackages_test.cc include $(PROGRAM_H) +# test cdroms index reduction for source.list +PROGRAM = CdromReduceSourceList${BASENAME} +SLIBS = -lapt-pkg +SOURCE = cdromreducesourcelist_test.cc +include $(PROGRAM_H) + # text IndexCopy::ConvertToSourceList PROGRAM = IndexCopyToSourceList${BASENAME} SLIBS = -lapt-pkg -- 2.20.1