From 6fd4b4c0b693b52cb8b593b76e5b60f77e500454 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 11 Feb 2016 22:54:49 +0100 Subject: always download changelogs into /tmp first MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pkgAcqChangelog has the default behaviour of downloading a changelog to a temporary directory (inside /tmp, not /tmp directly), which is cleaned up on shutdown, but this can be overridden to store the changelog more permanently – but that caries a permission problem. For changelog we can 'easily' solve this by always downloading to a temporary directory and only move it out of there on done. --- apt-pkg/acquire-item.cc | 56 ++++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 24 deletions(-) (limited to 'apt-pkg/acquire-item.cc') diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index 2057b7287..03baa9751 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -3076,9 +3076,14 @@ std::string pkgAcqArchive::ShortDesc() const /*{{{*/ pkgAcqArchive::~pkgAcqArchive() {} // AcqChangelog::pkgAcqChangelog - Constructors /*{{{*/ +class pkgAcqChangelog::Private +{ + public: + std::string FinalFile; +}; pkgAcqChangelog::pkgAcqChangelog(pkgAcquire * const Owner, pkgCache::VerIterator const &Ver, std::string const &DestDir, std::string const &DestFilename) : - pkgAcquire::Item(Owner), d(NULL), SrcName(Ver.SourcePkgName()), SrcVersion(Ver.SourceVerStr()) + pkgAcquire::Item(Owner), d(new pkgAcqChangelog::Private()), SrcName(Ver.SourcePkgName()), SrcVersion(Ver.SourceVerStr()) { Desc.URI = URI(Ver); Init(DestDir, DestFilename); @@ -3087,7 +3092,7 @@ pkgAcqChangelog::pkgAcqChangelog(pkgAcquire * const Owner, pkgCache::VerIterator pkgAcqChangelog::pkgAcqChangelog(pkgAcquire * const Owner, pkgCache::RlsFileIterator const &RlsFile, char const * const Component, char const * const SrcName, char const * const SrcVersion, const string &DestDir, const string &DestFilename) : - pkgAcquire::Item(Owner), d(NULL), SrcName(SrcName), SrcVersion(SrcVersion) + pkgAcquire::Item(Owner), d(new pkgAcqChangelog::Private()), SrcName(SrcName), SrcVersion(SrcVersion) { Desc.URI = URI(RlsFile, Component, SrcName, SrcVersion); Init(DestDir, DestFilename); @@ -3095,7 +3100,7 @@ pkgAcqChangelog::pkgAcqChangelog(pkgAcquire * const Owner, pkgCache::RlsFileIter pkgAcqChangelog::pkgAcqChangelog(pkgAcquire * const Owner, std::string const &URI, char const * const SrcName, char const * const SrcVersion, const string &DestDir, const string &DestFilename) : - pkgAcquire::Item(Owner), d(NULL), SrcName(SrcName), SrcVersion(SrcVersion) + pkgAcquire::Item(Owner), d(new pkgAcqChangelog::Private()), SrcName(SrcName), SrcVersion(SrcVersion) { Desc.URI = URI; Init(DestDir, DestFilename); @@ -3116,30 +3121,30 @@ void pkgAcqChangelog::Init(std::string const &DestDir, std::string const &DestFi return; } - if (DestDir.empty()) - { - std::string const SandboxUser = _config->Find("APT::Sandbox::User"); - std::string const systemTemp = GetTempDir(SandboxUser); - char tmpname[100]; - snprintf(tmpname, sizeof(tmpname), "%s/apt-changelog-XXXXXX", systemTemp.c_str()); - if (NULL == mkdtemp(tmpname)) - { - _error->Errno("mkdtemp", "mkdtemp failed in changelog acquire of %s %s", SrcName.c_str(), SrcVersion.c_str()); - Status = StatError; - return; - } - DestFile = TemporaryDirectory = tmpname; + std::string DestFileName; + if (DestFilename.empty()) + DestFileName = flCombine(DestFile, SrcName + ".changelog"); + else + DestFileName = flCombine(DestFile, DestFilename); - ChangeOwnerAndPermissionOfFile("Item::QueueURI", DestFile.c_str(), - SandboxUser.c_str(), "root", 0700); + std::string const SandboxUser = _config->Find("APT::Sandbox::User"); + std::string const systemTemp = GetTempDir(SandboxUser); + char tmpname[1000]; + snprintf(tmpname, sizeof(tmpname), "%s/apt-changelog-XXXXXX", systemTemp.c_str()); + if (NULL == mkdtemp(tmpname)) + { + _error->Errno("mkdtemp", "mkdtemp failed in changelog acquire of %s %s", SrcName.c_str(), SrcVersion.c_str()); + Status = StatError; + return; } - else - DestFile = DestDir; + TemporaryDirectory = tmpname; - if (DestFilename.empty()) - DestFile = flCombine(DestFile, SrcName + ".changelog"); - else - DestFile = flCombine(DestFile, DestFilename); + ChangeOwnerAndPermissionOfFile("Item::QueueURI", TemporaryDirectory.c_str(), + SandboxUser.c_str(), "root", 0700); + + DestFile = flCombine(TemporaryDirectory, DestFileName); + if (DestDir.empty() == false) + d->FinalFile = flCombine(DestDir, DestFileName); Desc.ShortDesc = "Changelog"; strprintf(Desc.Description, "%s %s %s Changelog", URI::SiteOnly(Desc.URI).c_str(), SrcName.c_str(), SrcVersion.c_str()); @@ -3294,6 +3299,8 @@ void pkgAcqChangelog::Done(string const &Message,HashStringList const &CalcHashe pkgAcquire::MethodConfig const * const Cnf) { Item::Done(Message,CalcHashes,Cnf); + if (d->FinalFile.empty() == false) + Rename(DestFile, d->FinalFile); Complete = true; } @@ -3305,6 +3312,7 @@ pkgAcqChangelog::~pkgAcqChangelog() /*{{{*/ RemoveFile("~pkgAcqChangelog", DestFile); rmdir(TemporaryDirectory.c_str()); } + delete d; } /*}}}*/ -- cgit v1.2.3