From 915f0520645f68dda1aea1ddfd7e7a413e1f3e09 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Fri, 15 Oct 2010 17:54:36 +0200 Subject: add test case for having no indexes, and fix regression in that case --- apt-pkg/deb/debindexfile.cc | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index a89a2574f..af1209ccb 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -149,11 +149,20 @@ bool debSourcesIndex::Exists() const /* */ unsigned long debSourcesIndex::Size() const { + unsigned long size = 0; + + /* we need to ignore errors here; if the lists are absent, just return 0 */ + _error->PushToStack(); + FileFd f = FileFd (IndexFile("Sources"), FileFd::ReadOnlyGzip); + if (!f.Failed()) + size = f.Size(); - if (f.Failed()) - return 0; - return f.Size(); + if (_error->PendingError() == true) + size = 0; + _error->RevertToStack(); + + return size; } /*}}}*/ @@ -269,11 +278,20 @@ bool debPackagesIndex::Exists() const /* This is really only used for progress reporting. */ unsigned long debPackagesIndex::Size() const { + unsigned long size = 0; + + /* we need to ignore errors here; if the lists are absent, just return 0 */ + _error->PushToStack(); + FileFd f = FileFd (IndexFile("Packages"), FileFd::ReadOnlyGzip); + if (!f.Failed()) + size = f.Size(); - if (f.Failed()) - return 0; - return f.Size(); + if (_error->PendingError() == true) + size = 0; + _error->RevertToStack(); + + return size; } /*}}}*/ // PackagesIndex::Merge - Load the index file into a cache /*{{{*/ @@ -460,12 +478,20 @@ bool debTranslationsIndex::Exists() const /* This is really only used for progress reporting. */ unsigned long debTranslationsIndex::Size() const { + unsigned long size = 0; + + /* we need to ignore errors here; if the lists are absent, just return 0 */ + _error->PushToStack(); + FileFd f = FileFd (IndexFile(Language), FileFd::ReadOnlyGzip); + if (!f.Failed()) + size = f.Size(); - if (f.Failed()) - return 0; + if (_error->PendingError() == true) + size = 0; + _error->RevertToStack(); - return f.Size(); + return size; } /*}}}*/ // TranslationsIndex::Merge - Load the index file into a cache /*{{{*/ -- cgit v1.2.3-70-g09d2