X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/1bc849af8f694ab80887bd0e9b94280f78771dbc..68ba0b7f4e1c03edfb6f621e7e7314ea610af96b:/apt-pkg/clean.cc diff --git a/apt-pkg/clean.cc b/apt-pkg/clean.cc index db47b1cc4..6edce5b6d 100644 --- a/apt-pkg/clean.cc +++ b/apt-pkg/clean.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: clean.cc,v 1.1 1999/02/01 08:11:57 jgg Exp $ +// $Id: clean.cc,v 1.4 2001/02/20 07:03:17 jgg Exp $ /* ###################################################################### Clean - Clean out downloaded directories @@ -8,34 +8,45 @@ ##################################################################### */ /*}}}*/ // Includes /*{{{*/ -#ifdef __GNUG__ -#pragma implementation "apt-pkg/clean.h" -#endif +#include #include #include #include +#include +#include +#include +#include +#include +#include +#include #include #include #include - /*}}}*/ +#include + /*}}}*/ // ArchiveCleaner::Go - Perform smart cleanup of the archive /*{{{*/ // --------------------------------------------------------------------- /* Scan the directory for files to erase, we check the version information against our database to see if it is interesting */ -bool pkgArchiveCleaner::Go(string Dir,pkgCache &Cache) +bool pkgArchiveCleaner::Go(std::string Dir,pkgCache &Cache) { - DIR *D = opendir(Dir.c_str()); + bool CleanInstalled = _config->FindB("APT::Clean-Installed",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()); - - string StartDir = SafeGetCWD(); + return _error->Errno("opendir",_("Unable to read %s"),Dir.c_str()); + + std::string StartDir = SafeGetCWD(); if (chdir(Dir.c_str()) != 0) { closedir(D); - return _error->Errno("chdir","Unable to change to ",Dir.c_str()); + return _error->Errno("chdir",_("Unable to change to %s"),Dir.c_str()); } for (struct dirent *Dir = readdir(D); Dir != 0; Dir = readdir(D)) @@ -49,48 +60,59 @@ bool pkgArchiveCleaner::Go(string Dir,pkgCache &Cache) struct stat St; if (stat(Dir->d_name,&St) != 0) - return _error->Errno("stat","Unable to stat %s.",Dir->d_name); - + { + _error->Errno("stat",_("Unable to stat %s."),Dir->d_name); + closedir(D); + if (chdir(StartDir.c_str()) != 0) + return _error->Errno("chdir", _("Unable to change to %s"), StartDir.c_str()); + return false; + } + // Grab the package name const char *I = Dir->d_name; for (; *I != 0 && *I != '_';I++); if (*I != '_') continue; - string Pkg = DeQuoteString(string(Dir->d_name,I-Dir->d_name)); + std::string Pkg = DeQuoteString(std::string(Dir->d_name,I-Dir->d_name)); // Grab the version const char *Start = I + 1; for (I = Start; *I != 0 && *I != '_';I++); if (*I != '_') continue; - string Ver = DeQuoteString(string(Start,I-Start)); + std::string Ver = DeQuoteString(std::string(Start,I-Start)); // Grab the arch Start = I + 1; for (I = Start; *I != 0 && *I != '.' ;I++); if (*I != '.') continue; - string Arch = DeQuoteString(string(Start,I-Start)); - + std::string const Arch = DeQuoteString(std::string(Start,I-Start)); + + // ignore packages of unconfigured architectures + if (APT::Configuration::checkArchitecture(Arch) == false) + continue; + // Lookup the package - pkgCache::PkgIterator P = Cache.FindPkg(Pkg); + pkgCache::PkgIterator P = Cache.FindPkg(Pkg, Arch); if (P.end() != true) { pkgCache::VerIterator V = P.VersionList(); - for (; V.end() == false; V++) + for (; V.end() == false; ++V) { // See if we can fetch this version at all bool IsFetchable = false; for (pkgCache::VerFileIterator J = V.FileList(); - J.end() == false; J++) + J.end() == false; ++J) { - if ((J.File()->Flags & pkgCache::Flag::NotSource) != 0) + if (CleanInstalled == true && + (J.File()->Flags & pkgCache::Flag::NotSource) != 0) continue; IsFetchable = true; break; } - // See if this verison matches the file + // See if this version matches the file if (IsFetchable == true && Ver == V.VerStr()) break; } @@ -101,11 +123,13 @@ bool pkgArchiveCleaner::Go(string Dir,pkgCache &Cache) } Erase(Dir->d_name,Pkg,Ver,St); - unlink(Dir->d_name); }; - chdir(StartDir.c_str()); closedir(D); - return true; + if (chdir(StartDir.c_str()) != 0) + return _error->Errno("chdir", _("Unable to change to %s"), StartDir.c_str()); + return true; } /*}}}*/ + +APT_CONST pkgArchiveCleaner::~pkgArchiveCleaner() {}