summaryrefslogtreecommitdiff
path: root/apt-pkg/acquire.cc
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg/acquire.cc')
-rw-r--r--apt-pkg/acquire.cc113
1 files changed, 67 insertions, 46 deletions
diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc
index b62c50c00..05f22f243 100644
--- a/apt-pkg/acquire.cc
+++ b/apt-pkg/acquire.cc
@@ -15,35 +15,35 @@
// Include Files /*{{{*/
#include <config.h>
-#include <apt-pkg/acquire.h>
#include <apt-pkg/acquire-item.h>
#include <apt-pkg/acquire-worker.h>
+#include <apt-pkg/acquire.h>
#include <apt-pkg/configuration.h>
#include <apt-pkg/error.h>
-#include <apt-pkg/strutl.h>
#include <apt-pkg/fileutl.h>
+#include <apt-pkg/strutl.h>
#include <algorithm>
+#include <iomanip>
+#include <iostream>
+#include <memory>
#include <numeric>
+#include <sstream>
#include <string>
#include <vector>
-#include <iostream>
-#include <sstream>
-#include <iomanip>
-#include <memory>
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <grp.h>
+#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <pwd.h>
-#include <grp.h>
-#include <dirent.h>
-#include <sys/time.h>
#include <sys/select.h>
-#include <errno.h>
#include <sys/stat.h>
+#include <sys/time.h>
+#include <unistd.h>
#include <apti18n.h>
/*}}}*/
@@ -770,42 +770,34 @@ bool pkgAcquire::Clean(string Dir)
if(Dir == "/")
return _error->Error(_("Clean of %s is not supported"), Dir.c_str());
- DIR *D = opendir(Dir.c_str());
- if (D == 0)
+ int const dirfd = open(Dir.c_str(), O_RDONLY | O_DIRECTORY | O_CLOEXEC);
+ if (dirfd == -1)
+ return _error->Errno("open",_("Unable to read %s"),Dir.c_str());
+ DIR * const D = fdopendir(dirfd);
+ if (D == nullptr)
return _error->Errno("opendir",_("Unable to read %s"),Dir.c_str());
-
- string StartDir = SafeGetCWD();
- if (chdir(Dir.c_str()) != 0)
- {
- closedir(D);
- return _error->Errno("chdir",_("Unable to change to %s"),Dir.c_str());
- }
-
- for (struct dirent *Dir = readdir(D); Dir != 0; Dir = readdir(D))
+
+ for (struct dirent *E = readdir(D); E != nullptr; E = readdir(D))
{
- // Skip some files..
- if (strcmp(Dir->d_name,"lock") == 0 ||
- strcmp(Dir->d_name,"partial") == 0 ||
- strcmp(Dir->d_name,"lost+found") == 0 ||
- strcmp(Dir->d_name,".") == 0 ||
- strcmp(Dir->d_name,"..") == 0)
+ // Skip some entries
+ if (strcmp(E->d_name,"lock") == 0 ||
+ strcmp(E->d_name,"partial") == 0 ||
+ strcmp(E->d_name,"lost+found") == 0 ||
+ strcmp(E->d_name,".") == 0 ||
+ strcmp(E->d_name,"..") == 0)
continue;
-
- // Look in the get list
- ItemCIterator I = Items.begin();
- for (; I != Items.end(); ++I)
- if (flNotDir((*I)->DestFile) == Dir->d_name)
- break;
-
- // Nothing found, nuke it
- if (I == Items.end())
- RemoveFile("Clean", Dir->d_name);
- };
-
+
+ // Look in the get list and if not found nuke
+ if (std::any_of(Items.cbegin(), Items.cend(),
+ [&E](pkgAcquire::Item const * const I) {
+ return flNotDir(I->DestFile) == E->d_name;
+ }) == false)
+ {
+ RemoveFileAt("pkgAcquire::Clean", dirfd, E->d_name);
+ }
+ }
closedir(D);
- if (chdir(StartDir.c_str()) != 0)
- return _error->Errno("chdir",_("Unable to change to %s"),StartDir.c_str());
- return true;
+ return true;
}
/*}}}*/
// Acquire::TotalNeeded - Number of bytes to fetch /*{{{*/
@@ -1414,10 +1406,39 @@ void pkgAcquireStatus::Stop()
// ---------------------------------------------------------------------
/* This is used to get accurate final transfer rate reporting. */
void pkgAcquireStatus::Fetched(unsigned long long Size,unsigned long long Resume)
-{
+{
FetchedBytes += Size - Resume;
}
/*}}}*/
+bool pkgAcquireStatus::ReleaseInfoChanges(metaIndex const * const LastRelease, metaIndex const * const CurrentRelease, std::vector<ReleaseInfoChange> &&Changes)/*{{{*/
+{
+ auto const virt = dynamic_cast<pkgAcquireStatus2*>(this);
+ if (virt != nullptr)
+ return virt->ReleaseInfoChanges(LastRelease, CurrentRelease, std::move(Changes));
+ return ReleaseInfoChangesAsGlobalErrors(std::move(Changes));
+}
+ /*}}}*/
+bool pkgAcquireStatus::ReleaseInfoChangesAsGlobalErrors(std::vector<ReleaseInfoChange> &&Changes)/*{{{*/
+{
+ bool AllOkay = true;
+ for (auto const &c: Changes)
+ if (c.DefaultAction)
+ _error->Notice("%s", c.Message.c_str());
+ else
+ {
+ _error->Error("%s", c.Message.c_str());
+ AllOkay = false;
+ }
+ return AllOkay;
+}
+ /*}}}*/
+bool pkgAcquireStatus2::ReleaseInfoChanges(metaIndex const * const, metaIndex const * const, std::vector<ReleaseInfoChange> &&Changes)
+{
+ return ReleaseInfoChangesAsGlobalErrors(std::move(Changes));
+}
+pkgAcquireStatus2::pkgAcquireStatus2() : pkgAcquireStatus() {}
+pkgAcquireStatus2::~pkgAcquireStatus2() {}
+
pkgAcquire::UriIterator::UriIterator(pkgAcquire::Queue *Q) : d(NULL), CurQ(Q), CurItem(0)
{