From d0cfa8adbdd74ad7e363019739c77e713dc982e5 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 16 Apr 2014 14:43:08 +0200 Subject: make the TotalFiles more reliable in apt-get update --- apt-pkg/acquire.cc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'apt-pkg/acquire.cc') diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index a187a00ae..2b427ccd3 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -832,6 +832,9 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner) if ((*I)->Local == true) continue; + // see if the method tells us to expect more + TotalItems += (*I)->ExpectedAdditionalItems; + TotalBytes += (*I)->FileSize; if ((*I)->Complete == true) CurrentBytes += (*I)->FileSize; @@ -901,12 +904,17 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner) snprintf(msg,sizeof(msg), _("Retrieving file %li of %li"), i, TotalItems); - + // calculate the percentage, if we have too little data assume 0% + int Percent; + if (TotalBytes < 1*1024) + Percent = 0; + else + Percent = (CurrentBytes/float(TotalBytes)*100.0); // build the status str status << "dlstatus:" << i - << ":" << (CurrentBytes/float(TotalBytes)*100.0) - << ":" << msg - << endl; + << ":" << Percent + << ":" << msg + << endl; std::string const dlstatus = status.str(); FileFd::Write(fd, dlstatus.c_str(), dlstatus.size()); -- cgit v1.2.3 From 1dca8dc55c1fcf4bda07a7e8285de7f225448697 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 16 Apr 2014 15:28:23 +0200 Subject: load the size from the metaindex into the fetcher to have even more accurate progress information --- apt-pkg/acquire.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'apt-pkg/acquire.cc') diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 2b427ccd3..9fc40752f 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -905,8 +905,11 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner) // calculate the percentage, if we have too little data assume 0% + // FIXME: the 5k is totally arbitrary + // FIXME2: instead, use a algorithm where 50% is based on total bytes + // and the other 50% on total files int Percent; - if (TotalBytes < 1*1024) + if (TotalBytes < 5*1024) Percent = 0; else Percent = (CurrentBytes/float(TotalBytes)*100.0); -- cgit v1.2.3 From c62f7898b6f37b8e4b076ae3c40d56d22a884efe Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 16 Apr 2014 16:34:01 +0200 Subject: add Debug::acquire::progress debug option and fixme for index file loading with the correct extension --- apt-pkg/acquire.cc | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'apt-pkg/acquire.cc') diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 9fc40752f..46d5e6386 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -846,6 +846,7 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner) unsigned long long ResumeSize = 0; for (pkgAcquire::Worker *I = Owner->WorkersBegin(); I != 0; I = Owner->WorkerStep(I)) + { if (I->CurrentItem != 0 && I->CurrentItem->Owner->Complete == false) { CurrentBytes += I->CurrentSize; @@ -856,7 +857,14 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner) I->CurrentItem->Owner->Complete == false) TotalBytes += I->CurrentSize; } + } + // debug + if (_config->FindB("Debug::acquire::progress", false) == true) + std::clog << " Bytes: " + << SizeToStr(CurrentBytes) << " / " << SizeToStr(TotalBytes) + << std::endl; + // Normalize the figures and account for unknown size downloads if (TotalBytes <= 0) TotalBytes = 1; -- cgit v1.2.3 From 96c6cab1fd5a5de19fbd552b42e1dd1c08417946 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 16 Apr 2014 17:41:11 +0200 Subject: calculate Percent as part of pkgAcquireStatus to provide a weighted percent for both items and bytes --- apt-pkg/acquire.cc | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'apt-pkg/acquire.cc') diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 46d5e6386..37964c943 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -859,12 +860,6 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner) } } - // debug - if (_config->FindB("Debug::acquire::progress", false) == true) - std::clog << " Bytes: " - << SizeToStr(CurrentBytes) << " / " << SizeToStr(TotalBytes) - << std::endl; - // Normalize the figures and account for unknown size downloads if (TotalBytes <= 0) TotalBytes = 1; @@ -874,6 +869,12 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner) // Wha?! Is not supposed to happen. if (CurrentBytes > TotalBytes) CurrentBytes = TotalBytes; + + // debug + if (_config->FindB("Debug::acquire::progress", false) == true) + std::clog << " Bytes: " + << SizeToStr(CurrentBytes) << " / " << SizeToStr(TotalBytes) + << std::endl; // Compute the CPS struct timeval NewTime; @@ -894,6 +895,15 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner) Time = NewTime; } + // calculate the percentage, if we have too little data assume 0% + // FIXME: the 5k is totally arbitrary + if (TotalBytes < 5*1024) + Percent = 0; + else + // use both files and bytes because bytes can be unreliable + Percent = (0.8 * (CurrentBytes/float(TotalBytes)*100.0) + + 0.2 * (CurrentItems/float(TotalItems)*100.0)); + int fd = _config->FindI("APT::Status-Fd",-1); if(fd > 0) { @@ -911,19 +921,9 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner) else snprintf(msg,sizeof(msg), _("Retrieving file %li of %li"), i, TotalItems); - - // calculate the percentage, if we have too little data assume 0% - // FIXME: the 5k is totally arbitrary - // FIXME2: instead, use a algorithm where 50% is based on total bytes - // and the other 50% on total files - int Percent; - if (TotalBytes < 5*1024) - Percent = 0; - else - Percent = (CurrentBytes/float(TotalBytes)*100.0); // build the status str status << "dlstatus:" << i - << ":" << Percent + << ":" << std::setprecision(3) << Percent << ":" << msg << endl; -- cgit v1.2.3 From c6e9cc582c7093b08c7c057c1f7885eb07e06959 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 8 May 2014 09:43:44 +0200 Subject: check for UnfetchedReleaseFiles when calculating the update percent value --- apt-pkg/acquire.cc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'apt-pkg/acquire.cc') diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 37964c943..57cbba169 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -822,7 +822,9 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner) // Compute the total number of bytes to fetch unsigned int Unknown = 0; unsigned int Count = 0; - for (pkgAcquire::ItemCIterator I = Owner->ItemsBegin(); I != Owner->ItemsEnd(); + bool UnfetchedReleaseFiles = false; + for (pkgAcquire::ItemCIterator I = Owner->ItemsBegin(); + I != Owner->ItemsEnd(); ++I, ++Count) { TotalItems++; @@ -836,6 +838,10 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner) // see if the method tells us to expect more TotalItems += (*I)->ExpectedAdditionalItems; + // check if there are unfetched Release files + if ((*I)->Complete == false && (*I)->ExpectedAdditionalItems > 0) + UnfetchedReleaseFiles = true; + TotalBytes += (*I)->FileSize; if ((*I)->Complete == true) CurrentBytes += (*I)->FileSize; @@ -895,9 +901,8 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner) Time = NewTime; } - // calculate the percentage, if we have too little data assume 0% - // FIXME: the 5k is totally arbitrary - if (TotalBytes < 5*1024) + // calculate the percentage, if we have too little data assume 1% + if (TotalBytes > 0 && UnfetchedReleaseFiles) Percent = 0; else // use both files and bytes because bytes can be unreliable -- cgit v1.2.3 From 10ecfe4f8a617ab285abd99d67917ae332ed2e4a Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 8 Jul 2014 11:27:01 +0200 Subject: Do not clean "/" in pkgAcquire::Clean/pkgArchiveCleaner Having "/" here is most likely a user configuration error and may cause removal of import symlinks like /vmlinuz Closes: #753531 --- apt-pkg/acquire.cc | 3 +++ 1 file changed, 3 insertions(+) (limited to 'apt-pkg/acquire.cc') diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index a187a00ae..057bc24cd 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -486,6 +486,9 @@ bool pkgAcquire::Clean(string Dir) if (DirectoryExists(Dir) == false) return true; + if(Dir == "/") + return _error->Error(_("Clean of %s is not supported"), Dir.c_str()); + DIR *D = opendir(Dir.c_str()); if (D == 0) return _error->Errno("opendir",_("Unable to read %s"),Dir.c_str()); -- cgit v1.2.3 From 564720959e4ae47921b795fe6c5ce46e1e1bdc95 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 18 Jul 2014 23:21:46 +0200 Subject: WIP transaction based update --- apt-pkg/acquire.cc | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'apt-pkg/acquire.cc') diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 8467dab5b..2e2e39d51 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -37,6 +37,7 @@ #include #include #include +#include #include /*}}}*/ @@ -168,6 +169,55 @@ void pkgAcquire::Remove(Item *Itm) } } /*}}}*/ +// Acquire::AbortTransaction - Remove a transaction /*{{{*/ +void pkgAcquire::AbortTransaction(unsigned long TransactionID) +{ + if(_config->FindB("Debug::Acquire::Transaction", false) == true) + std::clog << "AbortTransaction: " << TransactionID << std::endl; + + std::vector Transaction; + for (ItemIterator I = Items.begin(); I != Items.end(); ++I) + if((*I)->TransactionID == TransactionID) + Transaction.push_back(*I); + + for (std::vector::iterator I = Transaction.begin(); + I != Transaction.end(); ++I) + { + if(_config->FindB("Debug::Acquire::Transaction", false) == true) + std::clog << " Cancel: " << (*I)->DestFile << std::endl; + Dequeue(*I); + (*I)->Status = pkgAcquire::Item::StatError; + } +} + /*}}}*/ +// Acquire::CommitTransaction - Commit a transaction /*{{{*/ +void pkgAcquire::CommitTransaction(unsigned long TransactionID) +{ + if(_config->FindB("Debug::Acquire::Transaction", false) == true) + std::clog << "CommitTransaction: " << TransactionID << std::endl; + + std::vector Transaction; + for (ItemIterator I = Items.begin(); I != Items.end(); ++I) + if((*I)->TransactionID == TransactionID) + Transaction.push_back(*I); + + for (std::vector::iterator I = Transaction.begin(); + I != Transaction.end(); ++I) + { + if((*I)->PartialFile != "" && + (*I)->Status == pkgAcquire::Item::StatDone) + { + if(_config->FindB("Debug::Acquire::Transaction", false) == true) + std::clog << "mv " + << (*I)->PartialFile << " -> " + << (*I)->DestFile << std::endl; + Rename((*I)->PartialFile, (*I)->DestFile); + chmod((*I)->DestFile.c_str(),0644); + } + } +} + /*}}}*/ + // Acquire::Add - Add a worker /*{{{*/ // --------------------------------------------------------------------- /* A list of workers is kept so that the select loop can direct their FD -- cgit v1.2.3 From 47aca3cfc17ee23c37693b4e53c675a74b38decd Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 18 Jul 2014 23:41:29 +0200 Subject: add pkgAcquire::TransactionHasError() --- apt-pkg/acquire.cc | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'apt-pkg/acquire.cc') diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 2e2e39d51..4b82fa46d 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -185,11 +185,21 @@ void pkgAcquire::AbortTransaction(unsigned long TransactionID) { if(_config->FindB("Debug::Acquire::Transaction", false) == true) std::clog << " Cancel: " << (*I)->DestFile << std::endl; - Dequeue(*I); + //Dequeue(*I); (*I)->Status = pkgAcquire::Item::StatError; } } /*}}}*/ +bool pkgAcquire::TransactionHasError(unsigned long TransactionID) +{ + std::vector Transaction; + for (ItemIterator I = Items.begin(); I != Items.end(); ++I) + if((*I)->TransactionID == TransactionID) + if((*I)->Status == pkgAcquire::Item::StatError || + (*I)->Status == pkgAcquire::Item::StatAuthError) + return true; + return false; +} // Acquire::CommitTransaction - Commit a transaction /*{{{*/ void pkgAcquire::CommitTransaction(unsigned long TransactionID) { @@ -201,18 +211,25 @@ void pkgAcquire::CommitTransaction(unsigned long TransactionID) if((*I)->TransactionID == TransactionID) Transaction.push_back(*I); + // move new files into place *and* remove files that are not + // part of the transaction but are still on disk for (std::vector::iterator I = Transaction.begin(); I != Transaction.end(); ++I) { - if((*I)->PartialFile != "" && - (*I)->Status == pkgAcquire::Item::StatDone) + if((*I)->PartialFile != "") { if(_config->FindB("Debug::Acquire::Transaction", false) == true) std::clog << "mv " << (*I)->PartialFile << " -> " << (*I)->DestFile << std::endl; + Rename((*I)->PartialFile, (*I)->DestFile); chmod((*I)->DestFile.c_str(),0644); + } else { + if(_config->FindB("Debug::Acquire::Transaction", false) == true) + std::clog << "rm " + << (*I)->DestFile << std::endl; + unlink((*I)->DestFile.c_str()); } } } -- cgit v1.2.3 From 1f4dd8fd8489fbfd62c4d1667f159433a5f532b2 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 22 Jul 2014 11:35:30 +0200 Subject: WIP cleanup pkgAcqMetaSig --- apt-pkg/acquire.cc | 1 - 1 file changed, 1 deletion(-) (limited to 'apt-pkg/acquire.cc') diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 4b82fa46d..b14a54f0f 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -222,7 +222,6 @@ void pkgAcquire::CommitTransaction(unsigned long TransactionID) std::clog << "mv " << (*I)->PartialFile << " -> " << (*I)->DestFile << std::endl; - Rename((*I)->PartialFile, (*I)->DestFile); chmod((*I)->DestFile.c_str(),0644); } else { -- cgit v1.2.3 From e05672e88678f520b2db59599e939345ad0b6e53 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 31 Jul 2014 09:53:13 +0200 Subject: Rework TransactionID stuff --- apt-pkg/acquire.cc | 3 +++ 1 file changed, 3 insertions(+) (limited to 'apt-pkg/acquire.cc') diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index b14a54f0f..33afd8f1f 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -198,6 +198,7 @@ bool pkgAcquire::TransactionHasError(unsigned long TransactionID) if((*I)->Status == pkgAcquire::Item::StatError || (*I)->Status == pkgAcquire::Item::StatAuthError) return true; + return false; } // Acquire::CommitTransaction - Commit a transaction /*{{{*/ @@ -230,6 +231,8 @@ void pkgAcquire::CommitTransaction(unsigned long TransactionID) << (*I)->DestFile << std::endl; unlink((*I)->DestFile.c_str()); } + // mark that this transaction is finished + (*I)->TransactionID = 0; } } /*}}}*/ -- cgit v1.2.3 From 21638c3af355b3997fadd169495551568af6acfe Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 31 Jul 2014 19:24:36 +0200 Subject: fail early (again) on gpg sig failures --- apt-pkg/acquire.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'apt-pkg/acquire.cc') diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 33afd8f1f..15af5d6bd 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -195,8 +195,8 @@ bool pkgAcquire::TransactionHasError(unsigned long TransactionID) std::vector Transaction; for (ItemIterator I = Items.begin(); I != Items.end(); ++I) if((*I)->TransactionID == TransactionID) - if((*I)->Status == pkgAcquire::Item::StatError || - (*I)->Status == pkgAcquire::Item::StatAuthError) + if((*I)->Status != pkgAcquire::Item::StatDone && + (*I)->Status != pkgAcquire::Item::StatIdle) return true; return false; -- cgit v1.2.3 From 183160cb20cd4aa86e78657bf060bf688edce703 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 1 Aug 2014 17:15:53 +0200 Subject: make errors more consistent --- apt-pkg/acquire.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'apt-pkg/acquire.cc') diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 15af5d6bd..be4e494e0 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -185,8 +185,9 @@ void pkgAcquire::AbortTransaction(unsigned long TransactionID) { if(_config->FindB("Debug::Acquire::Transaction", false) == true) std::clog << " Cancel: " << (*I)->DestFile << std::endl; - //Dequeue(*I); - (*I)->Status = pkgAcquire::Item::StatError; + // the transaction will abort, so stop anything that is idle + if ((*I)->Status == pkgAcquire::Item::StatIdle) + (*I)->Status = pkgAcquire::Item::StatDone; } } /*}}}*/ -- cgit v1.2.3 From 715c65de1f132aff9f040f0640e985018e4b564e Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 17 Sep 2014 09:17:49 +0200 Subject: use pkgAcqMetaBase as the transactionManager --- apt-pkg/acquire.cc | 69 ------------------------------------------------------ 1 file changed, 69 deletions(-) (limited to 'apt-pkg/acquire.cc') diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index be4e494e0..9060d492b 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -169,75 +169,6 @@ void pkgAcquire::Remove(Item *Itm) } } /*}}}*/ -// Acquire::AbortTransaction - Remove a transaction /*{{{*/ -void pkgAcquire::AbortTransaction(unsigned long TransactionID) -{ - if(_config->FindB("Debug::Acquire::Transaction", false) == true) - std::clog << "AbortTransaction: " << TransactionID << std::endl; - - std::vector Transaction; - for (ItemIterator I = Items.begin(); I != Items.end(); ++I) - if((*I)->TransactionID == TransactionID) - Transaction.push_back(*I); - - for (std::vector::iterator I = Transaction.begin(); - I != Transaction.end(); ++I) - { - if(_config->FindB("Debug::Acquire::Transaction", false) == true) - std::clog << " Cancel: " << (*I)->DestFile << std::endl; - // the transaction will abort, so stop anything that is idle - if ((*I)->Status == pkgAcquire::Item::StatIdle) - (*I)->Status = pkgAcquire::Item::StatDone; - } -} - /*}}}*/ -bool pkgAcquire::TransactionHasError(unsigned long TransactionID) -{ - std::vector Transaction; - for (ItemIterator I = Items.begin(); I != Items.end(); ++I) - if((*I)->TransactionID == TransactionID) - if((*I)->Status != pkgAcquire::Item::StatDone && - (*I)->Status != pkgAcquire::Item::StatIdle) - return true; - - return false; -} -// Acquire::CommitTransaction - Commit a transaction /*{{{*/ -void pkgAcquire::CommitTransaction(unsigned long TransactionID) -{ - if(_config->FindB("Debug::Acquire::Transaction", false) == true) - std::clog << "CommitTransaction: " << TransactionID << std::endl; - - std::vector Transaction; - for (ItemIterator I = Items.begin(); I != Items.end(); ++I) - if((*I)->TransactionID == TransactionID) - Transaction.push_back(*I); - - // move new files into place *and* remove files that are not - // part of the transaction but are still on disk - for (std::vector::iterator I = Transaction.begin(); - I != Transaction.end(); ++I) - { - if((*I)->PartialFile != "") - { - if(_config->FindB("Debug::Acquire::Transaction", false) == true) - std::clog << "mv " - << (*I)->PartialFile << " -> " - << (*I)->DestFile << std::endl; - Rename((*I)->PartialFile, (*I)->DestFile); - chmod((*I)->DestFile.c_str(),0644); - } else { - if(_config->FindB("Debug::Acquire::Transaction", false) == true) - std::clog << "rm " - << (*I)->DestFile << std::endl; - unlink((*I)->DestFile.c_str()); - } - // mark that this transaction is finished - (*I)->TransactionID = 0; - } -} - /*}}}*/ - // Acquire::Add - Add a worker /*{{{*/ // --------------------------------------------------------------------- /* A list of workers is kept so that the select loop can direct their FD -- cgit v1.2.3 From 25613a61f6f3b9e54d5229af7e2278d0fa54bdd9 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 26 Sep 2014 22:16:26 +0200 Subject: fix: Member variable 'X' is not initialized in the constructor. Reported-By: cppcheck Git-Dch: Ignore --- apt-pkg/acquire.cc | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'apt-pkg/acquire.cc') diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 8467dab5b..f0a88a538 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -581,27 +581,18 @@ pkgAcquire::UriIterator pkgAcquire::UriEnd() // Acquire::MethodConfig::MethodConfig - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ -pkgAcquire::MethodConfig::MethodConfig() +pkgAcquire::MethodConfig::MethodConfig() : d(NULL), Next(0), SingleInstance(false), + Pipeline(false), SendConfig(false), LocalOnly(false), NeedsCleanup(false), + Removable(false) { - SingleInstance = false; - Pipeline = false; - SendConfig = false; - LocalOnly = false; - Removable = false; - Next = 0; } /*}}}*/ // Queue::Queue - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ -pkgAcquire::Queue::Queue(string Name,pkgAcquire *Owner) : Name(Name), - Owner(Owner) +pkgAcquire::Queue::Queue(string Name,pkgAcquire *Owner) : d(NULL), Next(0), + Name(Name), Items(0), Workers(0), Owner(Owner), PipeDepth(0), MaxPipeDepth(1) { - Items = 0; - Next = 0; - Workers = 0; - MaxPipeDepth = 1; - PipeDepth = 0; } /*}}}*/ // Queue::~Queue - Destructor /*{{{*/ @@ -805,7 +796,7 @@ void pkgAcquire::Queue::Bump() // AcquireStatus::pkgAcquireStatus - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ -pkgAcquireStatus::pkgAcquireStatus() : d(NULL), Update(true), MorePulses(false) +pkgAcquireStatus::pkgAcquireStatus() : d(NULL), Percent(0), Update(true), MorePulses(false) { Start(); } -- cgit v1.2.3 From 43acd01979039b248cb7f033b82e36d778d0ebec Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 27 Sep 2014 19:45:30 +0200 Subject: allow fetcher setup without directory creation apt-get download and changelog as well as apt-helper reuse the acquire system for their own proposes without requiring the directories the fetcher wants to create, which is a problem if you run them as non-root and the directories do not exist as it greets you with: E: Archives directory /var/cache/apt/archives/partial is missing. - Acquire (13: Permission denied) Closes: 762898 --- apt-pkg/acquire.cc | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'apt-pkg/acquire.cc') diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index f0a88a538..8119e4487 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -73,23 +73,27 @@ pkgAcquire::pkgAcquire(pkgAcquireStatus *Progress) : LockFD(-1), Queues(0), Wor // --------------------------------------------------------------------- /* Do everything needed to be a complete Acquire object and report the success (or failure) back so the user knows that something is wrong… */ -bool pkgAcquire::Setup(pkgAcquireStatus *Progress, string const &Lock) +bool pkgAcquire::Setup(pkgAcquireStatus *Progress, string const &Lock, + bool const createDirectories) { Log = Progress; // check for existence and possibly create auxiliary directories - string const listDir = _config->FindDir("Dir::State::lists"); - string const partialListDir = listDir + "partial/"; - string const archivesDir = _config->FindDir("Dir::Cache::Archives"); - string const partialArchivesDir = archivesDir + "partial/"; - - if (CreateAPTDirectoryIfNeeded(_config->FindDir("Dir::State"), partialListDir) == false && - CreateAPTDirectoryIfNeeded(listDir, partialListDir) == false) - return _error->Errno("Acquire", _("List directory %spartial is missing."), listDir.c_str()); - - if (CreateAPTDirectoryIfNeeded(_config->FindDir("Dir::Cache"), partialArchivesDir) == false && - CreateAPTDirectoryIfNeeded(archivesDir, partialArchivesDir) == false) - return _error->Errno("Acquire", _("Archives directory %spartial is missing."), archivesDir.c_str()); + if (createDirectories == true) + { + string const listDir = _config->FindDir("Dir::State::lists"); + string const partialListDir = listDir + "partial/"; + string const archivesDir = _config->FindDir("Dir::Cache::Archives"); + string const partialArchivesDir = archivesDir + "partial/"; + + if (CreateAPTDirectoryIfNeeded(_config->FindDir("Dir::State"), partialListDir) == false && + CreateAPTDirectoryIfNeeded(listDir, partialListDir) == false) + return _error->Errno("Acquire", _("List directory %spartial is missing."), listDir.c_str()); + + if (CreateAPTDirectoryIfNeeded(_config->FindDir("Dir::Cache"), partialArchivesDir) == false && + CreateAPTDirectoryIfNeeded(archivesDir, partialArchivesDir) == false) + return _error->Errno("Acquire", _("Archives directory %spartial is missing."), archivesDir.c_str()); + } if (Lock.empty() == true || _config->FindB("Debug::NoLocking", false) == true) return true; -- cgit v1.2.3 From 04a54261afd1c99686109f102afc83346c01c930 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 6 Oct 2014 11:15:03 +0200 Subject: ensure partial dirs are 0700 and owned by _apt:root Reworks the API involved in creating and setting up the fetcher to be a bit more pleasent to look at and work with as e.g. an empty string for no lock isn't very nice. With the lock we can also stop creating all our partial directories "just in case". This way we can also be a bit more aggressive with the partial directory itself as with a lock, we know we will gone need it. --- apt-pkg/acquire.cc | 78 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 23 deletions(-) (limited to 'apt-pkg/acquire.cc') diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index ec565fcfa..9dee1b3cf 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -27,17 +27,20 @@ #include #include #include +#include + #include #include #include #include -#include - +#include +#include #include #include #include #include #include +#include #include /*}}}*/ @@ -57,8 +60,8 @@ pkgAcquire::pkgAcquire() : LockFD(-1), Queues(0), Workers(0), Configs(0), Log(NU if (strcasecmp(Mode.c_str(),"access") == 0) QueueMode = QueueAccess; } -pkgAcquire::pkgAcquire(pkgAcquireStatus *Progress) : LockFD(-1), Queues(0), Workers(0), - Configs(0), Log(Progress), ToFetch(0), +pkgAcquire::pkgAcquire(pkgAcquireStatus *Progress) : LockFD(-1), Queues(0), Workers(0), + Configs(0), Log(NULL), ToFetch(0), Debug(_config->FindB("Debug::pkgAcquire",false)), Running(false) { @@ -67,40 +70,69 @@ pkgAcquire::pkgAcquire(pkgAcquireStatus *Progress) : LockFD(-1), Queues(0), Wor QueueMode = QueueHost; if (strcasecmp(Mode.c_str(),"access") == 0) QueueMode = QueueAccess; - Setup(Progress, ""); + SetLog(Progress); } /*}}}*/ -// Acquire::Setup - Delayed Constructor /*{{{*/ -// --------------------------------------------------------------------- -/* Do everything needed to be a complete Acquire object and report the - success (or failure) back so the user knows that something is wrong… */ -bool pkgAcquire::Setup(pkgAcquireStatus *Progress, string const &Lock, - bool const createDirectories) +// Acquire::GetLock - lock directory and prepare for action /*{{{*/ +static bool SetupAPTPartialDirectory(std::string const &grand, std::string const &parent) { - Log = Progress; + std::string const partial = parent + "partial"; + if (CreateAPTDirectoryIfNeeded(grand, partial) == false && + CreateAPTDirectoryIfNeeded(parent, partial) == false) + return false; - // check for existence and possibly create auxiliary directories - if (createDirectories == true) + if (getuid() == 0) // if we aren't root, we can't chown, so don't try it + { + struct passwd *pw = getpwnam("_apt"); + struct group *gr = getgrnam("root"); + if (pw != NULL && gr != NULL && chown(partial.c_str(), pw->pw_uid, gr->gr_gid) != 0) + _error->WarningE("SetupAPTPartialDirectory", "chown to _apt:root of directory %s failed", partial.c_str()); + } + if (chmod(partial.c_str(), 0700) != 0) + _error->WarningE("SetupAPTPartialDirectory", "chmod 0700 of directory %s failed", partial.c_str()); + + return true; +} +bool pkgAcquire::Setup(pkgAcquireStatus *Progress, string const &Lock) +{ + Log = Progress; + if (Lock.empty()) { string const listDir = _config->FindDir("Dir::State::lists"); - string const partialListDir = listDir + "partial/"; + if (SetupAPTPartialDirectory(_config->FindDir("Dir::State"), listDir) == false) + return _error->Errno("Acquire", _("List directory %spartial is missing."), listDir.c_str()); string const archivesDir = _config->FindDir("Dir::Cache::Archives"); - string const partialArchivesDir = archivesDir + "partial/"; + if (SetupAPTPartialDirectory(_config->FindDir("Dir::Cache"), archivesDir) == false) + return _error->Errno("Acquire", _("Archives directory %spartial is missing."), archivesDir.c_str()); + return true; + } + return GetLock(Lock); +} +bool pkgAcquire::GetLock(std::string const &Lock) +{ + if (Lock.empty() == true) + return false; - if (CreateAPTDirectoryIfNeeded(_config->FindDir("Dir::State"), partialListDir) == false && - CreateAPTDirectoryIfNeeded(listDir, partialListDir) == false) - return _error->Errno("Acquire", _("List directory %spartial is missing."), listDir.c_str()); + // check for existence and possibly create auxiliary directories + string const listDir = _config->FindDir("Dir::State::lists"); + string const archivesDir = _config->FindDir("Dir::Cache::Archives"); - if (CreateAPTDirectoryIfNeeded(_config->FindDir("Dir::Cache"), partialArchivesDir) == false && - CreateAPTDirectoryIfNeeded(archivesDir, partialArchivesDir) == false) + if (Lock == listDir) + { + if (SetupAPTPartialDirectory(_config->FindDir("Dir::State"), listDir) == false) + return _error->Errno("Acquire", _("List directory %spartial is missing."), listDir.c_str()); + } + if (Lock == archivesDir) + { + if (SetupAPTPartialDirectory(_config->FindDir("Dir::Cache"), archivesDir) == false) return _error->Errno("Acquire", _("Archives directory %spartial is missing."), archivesDir.c_str()); } - if (Lock.empty() == true || _config->FindB("Debug::NoLocking", false) == true) + if (_config->FindB("Debug::NoLocking", false) == true) return true; // Lock the directory this acquire object will work in - LockFD = GetLock(flCombine(Lock, "lock")); + LockFD = ::GetLock(flCombine(Lock, "lock")); if (LockFD == -1) return _error->Error(_("Unable to lock directory %s"), Lock.c_str()); -- cgit v1.2.3 From 862bafea48af2ceaf96345db237b461307a021f6 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 13 Oct 2014 08:05:57 +0200 Subject: do not inline virtual destructors with d-pointers Reimplementing an inline method is opening a can of worms we don't want to open if we ever want to us a d-pointer in those classes, so we do the only thing which can save us from hell: move the destructors into the cc sources and we are good. Technically not an ABI break as the methods inline or not do the same (nothing), so a program compiled against the old version still works with the new version (beside that this version is still in experimental, so nothing really has been build against this library anyway). Git-Dch: Ignore --- apt-pkg/acquire.cc | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'apt-pkg/acquire.cc') diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 9dee1b3cf..34c7f06de 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -1016,3 +1016,7 @@ void pkgAcquireStatus::Fetched(unsigned long long Size,unsigned long long Resume FetchedBytes += Size - Resume; } /*}}}*/ + +pkgAcquire::UriIterator::~UriIterator() {} +pkgAcquire::MethodConfig::~MethodConfig() {} +pkgAcquireStatus::~pkgAcquireStatus() {} -- cgit v1.2.3 From 9983999d294887046abf386adc31190700d89b61 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 13 Oct 2014 10:57:30 +0200 Subject: Fix backward compatiblity of the new pkgAcquireMethod::DropPrivsOrDie() Do not drop privileges in the methods when using a older version of libapt that does not support the chown magic in partial/ yet. To do this DropPrivileges() now will ignore a empty Apt::Sandbox::User. Cleanup all hardcoded _apt along the way. --- apt-pkg/acquire.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'apt-pkg/acquire.cc') diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 34c7f06de..3ef912600 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -83,10 +83,11 @@ static bool SetupAPTPartialDirectory(std::string const &grand, std::string const if (getuid() == 0) // if we aren't root, we can't chown, so don't try it { - struct passwd *pw = getpwnam("_apt"); + std::string SandboxUser = _config->Find("APT::Sandbox::User"); + struct passwd *pw = getpwnam(SandboxUser.c_str()); struct group *gr = getgrnam("root"); if (pw != NULL && gr != NULL && chown(partial.c_str(), pw->pw_uid, gr->gr_gid) != 0) - _error->WarningE("SetupAPTPartialDirectory", "chown to _apt:root of directory %s failed", partial.c_str()); + _error->WarningE("SetupAPTPartialDirectory", "chown to %s:root of directory %s failed", SandboxUser.c_str(), partial.c_str()); } if (chmod(partial.c_str(), 0700) != 0) _error->WarningE("SetupAPTPartialDirectory", "chmod 0700 of directory %s failed", partial.c_str()); -- cgit v1.2.3 From 9d653a6de2ca952247cc4e628256259d225570a6 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 13 Oct 2014 09:54:21 +0200 Subject: fix compile and tests error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I am pretty sure I did that before committing broken stuff… Git-Dch: Ignore --- apt-pkg/acquire.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'apt-pkg/acquire.cc') diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 3ef912600..1aa709381 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -1018,6 +1018,6 @@ void pkgAcquireStatus::Fetched(unsigned long long Size,unsigned long long Resume } /*}}}*/ -pkgAcquire::UriIterator::~UriIterator() {} -pkgAcquire::MethodConfig::~MethodConfig() {} -pkgAcquireStatus::~pkgAcquireStatus() {} +APT_CONST pkgAcquire::UriIterator::~UriIterator() {} +APT_CONST pkgAcquire::MethodConfig::~MethodConfig() {} +APT_CONST pkgAcquireStatus::~pkgAcquireStatus() {} -- cgit v1.2.3 From 1924b1e513b0619c177565d17475ea3747983f4f Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 21 Oct 2014 11:19:45 -0400 Subject: Ensure /etc/apt/auth.conf has _apt:root owner Ensure in SetupAPTPartialDirectory() that the /etc/apt/auth.conf file can be read by the priv sep apt methods. --- apt-pkg/acquire.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'apt-pkg/acquire.cc') diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 1aa709381..033fa9bd3 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -86,8 +86,16 @@ static bool SetupAPTPartialDirectory(std::string const &grand, std::string const std::string SandboxUser = _config->Find("APT::Sandbox::User"); struct passwd *pw = getpwnam(SandboxUser.c_str()); struct group *gr = getgrnam("root"); - if (pw != NULL && gr != NULL && chown(partial.c_str(), pw->pw_uid, gr->gr_gid) != 0) - _error->WarningE("SetupAPTPartialDirectory", "chown to %s:root of directory %s failed", SandboxUser.c_str(), partial.c_str()); + if (pw != NULL && gr != NULL) + { + // chown the partial dir + if(chown(partial.c_str(), pw->pw_uid, gr->gr_gid) != 0) + _error->WarningE("SetupAPTPartialDirectory", "chown to %s:root of directory %s failed", SandboxUser.c_str(), partial.c_str()); + // chown the auth.conf file + std::string AuthConf = _config->FindFile("Dir::Etc::netrc"); + if(chown(AuthConf.c_str(), pw->pw_uid, gr->gr_gid) != 0) + _error->WarningE("SetupAPTPartialDirectory", "chown to %s:root of file %s failed", SandboxUser.c_str(), AuthConf.c_str()); + } } if (chmod(partial.c_str(), 0700) != 0) _error->WarningE("SetupAPTPartialDirectory", "chmod 0700 of directory %s failed", partial.c_str()); -- cgit v1.2.3 From e845cde33c5d13a0e2dd924a388705a0738d4f96 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 22 Oct 2014 00:05:40 +0200 Subject: check that auth.conf exists before chowning it Git-Dch: Ignore --- apt-pkg/acquire.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'apt-pkg/acquire.cc') diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 033fa9bd3..1e20b74be 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -92,9 +92,10 @@ static bool SetupAPTPartialDirectory(std::string const &grand, std::string const if(chown(partial.c_str(), pw->pw_uid, gr->gr_gid) != 0) _error->WarningE("SetupAPTPartialDirectory", "chown to %s:root of directory %s failed", SandboxUser.c_str(), partial.c_str()); // chown the auth.conf file - std::string AuthConf = _config->FindFile("Dir::Etc::netrc"); - if(chown(AuthConf.c_str(), pw->pw_uid, gr->gr_gid) != 0) - _error->WarningE("SetupAPTPartialDirectory", "chown to %s:root of file %s failed", SandboxUser.c_str(), AuthConf.c_str()); + std::string const AuthConf = _config->FindFile("Dir::Etc::netrc"); + if(AuthConf.empty() == false && RealFileExists(AuthConf) && + chown(AuthConf.c_str(), pw->pw_uid, gr->gr_gid) != 0) + _error->WarningE("SetupAPTPartialDirectory", "chown to %s:root of file %s failed", SandboxUser.c_str(), AuthConf.c_str()); } } if (chmod(partial.c_str(), 0700) != 0) -- cgit v1.2.3 From 03aa08472dcd689572a46ce6efdb1dccf6136334 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 23 Oct 2014 01:28:05 +0200 Subject: chown finished partial files earlier partial files are chowned by the Item baseclass to let the methods work with them. Now, this baseclass is also responsible for chowning the files back to root instead of having various deeper levels do this. The consequence is that all overloaded Failed() methods now call the Item::Failed base as their first step. The same is done for Done(). The effect is that even in partial files usually don't belong to _apt anymore, helping sneakernets and reducing possibilities of a bad method modifying files not belonging to them. The change is supported by the framework not only supporting being run as root, but with proper permission management, too, so that privilege dropping can be tested with them. --- apt-pkg/acquire.cc | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) (limited to 'apt-pkg/acquire.cc') diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 1e20b74be..2c89c2dea 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -54,23 +54,38 @@ pkgAcquire::pkgAcquire() : LockFD(-1), Queues(0), Workers(0), Configs(0), Log(NU Debug(_config->FindB("Debug::pkgAcquire",false)), Running(false) { - string const Mode = _config->Find("Acquire::Queue-Mode","host"); - if (strcasecmp(Mode.c_str(),"host") == 0) - QueueMode = QueueHost; - if (strcasecmp(Mode.c_str(),"access") == 0) - QueueMode = QueueAccess; + Initialize(); } pkgAcquire::pkgAcquire(pkgAcquireStatus *Progress) : LockFD(-1), Queues(0), Workers(0), Configs(0), Log(NULL), ToFetch(0), Debug(_config->FindB("Debug::pkgAcquire",false)), Running(false) +{ + Initialize(); + SetLog(Progress); +} +void pkgAcquire::Initialize() { string const Mode = _config->Find("Acquire::Queue-Mode","host"); if (strcasecmp(Mode.c_str(),"host") == 0) QueueMode = QueueHost; if (strcasecmp(Mode.c_str(),"access") == 0) QueueMode = QueueAccess; - SetLog(Progress); + + // chown the auth.conf file as it will be accessed by our methods + std::string const SandboxUser = _config->Find("APT::Sandbox::User"); + if (getuid() == 0 && SandboxUser.empty() == false) // if we aren't root, we can't chown, so don't try it + { + struct passwd const * const pw = getpwnam(SandboxUser.c_str()); + struct group const * const gr = getgrnam("root"); + if (pw != NULL && gr != NULL) + { + std::string const AuthConf = _config->FindFile("Dir::Etc::netrc"); + if(AuthConf.empty() == false && RealFileExists(AuthConf) && + chown(AuthConf.c_str(), pw->pw_uid, gr->gr_gid) != 0) + _error->WarningE("SetupAPTPartialDirectory", "chown to %s:root of file %s failed", SandboxUser.c_str(), AuthConf.c_str()); + } + } } /*}}}*/ // Acquire::GetLock - lock directory and prepare for action /*{{{*/ @@ -81,21 +96,16 @@ static bool SetupAPTPartialDirectory(std::string const &grand, std::string const CreateAPTDirectoryIfNeeded(parent, partial) == false) return false; - if (getuid() == 0) // if we aren't root, we can't chown, so don't try it + std::string const SandboxUser = _config->Find("APT::Sandbox::User"); + if (getuid() == 0 && SandboxUser.empty() == false) // if we aren't root, we can't chown, so don't try it { - std::string SandboxUser = _config->Find("APT::Sandbox::User"); - struct passwd *pw = getpwnam(SandboxUser.c_str()); - struct group *gr = getgrnam("root"); + struct passwd const * const pw = getpwnam(SandboxUser.c_str()); + struct group const * const gr = getgrnam("root"); if (pw != NULL && gr != NULL) { // chown the partial dir if(chown(partial.c_str(), pw->pw_uid, gr->gr_gid) != 0) _error->WarningE("SetupAPTPartialDirectory", "chown to %s:root of directory %s failed", SandboxUser.c_str(), partial.c_str()); - // chown the auth.conf file - std::string const AuthConf = _config->FindFile("Dir::Etc::netrc"); - if(AuthConf.empty() == false && RealFileExists(AuthConf) && - chown(AuthConf.c_str(), pw->pw_uid, gr->gr_gid) != 0) - _error->WarningE("SetupAPTPartialDirectory", "chown to %s:root of file %s failed", SandboxUser.c_str(), AuthConf.c_str()); } } if (chmod(partial.c_str(), 0700) != 0) -- cgit v1.2.3 From 7e04a6bf23d857db60afd2ec3d0f4a8271b1c597 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 9 Nov 2014 19:04:54 +0100 Subject: use pkgAcquire::GetLock instead of own code Do the same with less code in apt-get. This especially ensures that the lock file (and the parent directories) exist before we are trying to lock. It also means that clean now creates the directories if they are missing so we returned to a proper clean state now. Git-Dch: Ignore --- apt-pkg/acquire.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'apt-pkg/acquire.cc') diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 2c89c2dea..07c4646f5 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -152,6 +152,8 @@ bool pkgAcquire::GetLock(std::string const &Lock) return true; // Lock the directory this acquire object will work in + if (LockFD != -1) + close(LockFD); LockFD = ::GetLock(flCombine(Lock, "lock")); if (LockFD == -1) return _error->Error(_("Unable to lock directory %s"), Lock.c_str()); -- cgit v1.2.3 From 8fe964f148344b8a55252fe52b6292a4ab86ea98 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 14 Nov 2014 18:01:09 +0100 Subject: create our cache and lib directory always with mode 755 We autocreate for a while now the last two directories in /var/lib/apt/lists (similar for /var/cache/apt/archives) which is very nice for systems having any of those on tmpfs or other non-persistent storage. This also means though that this creation is effected by the default umask, so for people with aggressive umasks like 027 the directories will be created with 750, which means all non-root users are left out, which is usually exactly what we want then this umask is set, but the cache and lib directories contain public knowledge. There isn't any need to protect them from viewers and they render apt completely useless if not readable. --- apt-pkg/acquire.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'apt-pkg/acquire.cc') diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 07c4646f5..0c815c005 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -92,8 +92,11 @@ void pkgAcquire::Initialize() static bool SetupAPTPartialDirectory(std::string const &grand, std::string const &parent) { std::string const partial = parent + "partial"; - if (CreateAPTDirectoryIfNeeded(grand, partial) == false && - CreateAPTDirectoryIfNeeded(parent, partial) == false) + mode_t const mode = umask(S_IWGRP | S_IWOTH); + bool const creation_fail = (CreateAPTDirectoryIfNeeded(grand, partial) == false && + CreateAPTDirectoryIfNeeded(parent, partial) == false); + umask(mode); + if (creation_fail == true) return false; std::string const SandboxUser = _config->Find("APT::Sandbox::User"); -- cgit v1.2.3