diff options
Diffstat (limited to 'apt-pkg')
-rw-r--r-- | apt-pkg/acquire-item.cc | 56 | ||||
-rw-r--r-- | apt-pkg/acquire-item.h | 3 | ||||
-rw-r--r-- | apt-pkg/acquire.cc | 2 |
3 files changed, 35 insertions, 26 deletions
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; } /*}}}*/ diff --git a/apt-pkg/acquire-item.h b/apt-pkg/acquire-item.h index 306b1772a..61f64c3a9 100644 --- a/apt-pkg/acquire-item.h +++ b/apt-pkg/acquire-item.h @@ -1055,7 +1055,8 @@ class pkgAcqArchive : public pkgAcquire::Item */ class pkgAcqChangelog : public pkgAcquire::Item { - void * const d; + class Private; + Private * const d; std::string TemporaryDirectory; std::string const SrcName; std::string const SrcVersion; diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index e515255ae..17ee691d7 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -559,7 +559,7 @@ static void CheckDropPrivsMustBeDisabled(pkgAcquire const &Fetcher) I != Fetcher.ItemsEnd(); ++I) { // no need to drop privileges for a complete file - if ((*I)->Complete == true) + if ((*I)->Complete == true || (*I)->Status != pkgAcquire::Item::StatIdle) continue; // if destination file is inaccessible all hope is lost for privilege dropping |