summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apt-pkg/acquire-item.cc55
-rw-r--r--apt-pkg/acquire-item.h9
2 files changed, 39 insertions, 25 deletions
diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc
index dbc1dfbe7..675a7ed41 100644
--- a/apt-pkg/acquire-item.cc
+++ b/apt-pkg/acquire-item.cc
@@ -1141,6 +1141,35 @@ void pkgAcqIndex::ReverifyAfterIMS()
QueueURI(Desc);
}
/*}}}*/
+
+// pkgAcqIndex::ValidateFile - Validate the downloaded file /*{{{*/
+// ---------------------------------------------------------------------
+bool pkgAcqIndex::ValidateFile(const std::string &FileName)
+{
+ // FIXME: this can go away once we only ever download stuff that
+ // has a valid hash and we never do GET based probing
+ // FIXME2: this also leaks debian-isms into the code and should go therefore
+
+ /* Always validate the index file for correctness (all indexes must
+ * have a Package field) (LP: #346386) (Closes: #627642)
+ */
+ FileFd fd(DestFile, FileFd::ReadOnly, FileFd::Extension);
+ // Only test for correctness if the content of the file is not empty
+ // (empty is ok)
+ if (fd.Size() > 0)
+ {
+ pkgTagSection sec;
+ pkgTagFile tag(&fd);
+
+ // all our current indexes have a field 'Package' in each section
+ if (_error->PendingError() == true ||
+ tag.Step(sec) == false ||
+ sec.Exists("Package") == false)
+ return false;
+ }
+ return true;
+}
+ /*}}}*/
// AcqIndex::Done - Finished a fetch /*{{{*/
// ---------------------------------------------------------------------
/* This goes through a number of states.. On the initial fetch the
@@ -1166,29 +1195,13 @@ void pkgAcqIndex::Done(string Message, unsigned long long Size,
return;
}
- // FIXME: this can go away once we only ever download stuff that
- // has a valid hash and we never do GET based probing
- //
- /* Always verify the index file for correctness (all indexes must
- * have a Package field) (LP: #346386) (Closes: #627642)
- */
- FileFd fd(DestFile, FileFd::ReadOnly, FileFd::Extension);
- // Only test for correctness if the content of the file is not empty
- // (empty is ok)
- if (fd.Size() > 0)
+ if(!ValidateFile(DestFile))
{
- pkgTagSection sec;
- pkgTagFile tag(&fd);
-
- // all our current indexes have a field 'Package' in each section
- if (_error->PendingError() == true || tag.Step(sec) == false || sec.Exists("Package") == false)
- {
- RenameOnError(InvalidFormat);
- Failed(Message, Cfg);
- return;
- }
+ RenameOnError(InvalidFormat);
+ Failed(Message, Cfg);
+ return;
}
-
+
// FIXME: can we void the "Erase" bool here as its very non-local?
std::string CompressedFile = _config->FindDir("Dir::State::lists") + "partial/";
CompressedFile += URItoFileName(RealURI);
diff --git a/apt-pkg/acquire-item.h b/apt-pkg/acquire-item.h
index e560da956..30a8850e4 100644
--- a/apt-pkg/acquire-item.h
+++ b/apt-pkg/acquire-item.h
@@ -283,7 +283,6 @@ class pkgAcquire::Item : public WeakPointable
/** \return \b true if this object is being fetched from a trusted source. */
virtual bool IsTrusted() const {return false;};
- // report mirror problems
/** \brief Report mirror problem
*
* This allows reporting mirror failures back to a centralized
@@ -293,7 +292,6 @@ class pkgAcquire::Item : public WeakPointable
*/
void ReportMirrorFailure(std::string FailCode);
-
/** \brief Initialize an item.
*
* Adds the item to the list of items known to the acquire
@@ -947,7 +945,6 @@ class pkgAcqIndex : public pkgAcqBaseIndex
*/
std::string CompressionExtension;
-
/** \brief Do the changes needed to fetch via AptByHash (if needed) */
void InitByHashIfNeeded(const std::string MetaKey);
@@ -961,11 +958,15 @@ class pkgAcqIndex : public pkgAcqBaseIndex
/** \brief Schedule file for verification after a IMS hit */
void ReverifyAfterIMS();
+ /** \brief Validate the downloaded index file */
+ bool ValidateFile(const std::string &FileName);
+
public:
// Specialized action members
virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
- virtual void Done(std::string Message,unsigned long long Size, HashStringList const &Hashes,
+ virtual void Done(std::string Message,unsigned long long Size,
+ HashStringList const &Hashes,
pkgAcquire::MethodConfig *Cnf);
virtual std::string Custom600Headers() const;
virtual std::string DescURI() {return Desc.URI;};