]>
git.saurik.com Git - apt.git/blob - apt-pkg/clean.cc
   1 // -*- mode: cpp; mode: fold -*- 
   3 // $Id: clean.cc,v 1.4 2001/02/20 07:03:17 jgg Exp $ 
   4 /* ###################################################################### 
   6    Clean - Clean out downloaded directories 
   8    ##################################################################### */ 
  13 #include <apt-pkg/clean.h> 
  14 #include <apt-pkg/strutl.h> 
  15 #include <apt-pkg/error.h> 
  16 #include <apt-pkg/configuration.h> 
  17 #include <apt-pkg/aptconfiguration.h> 
  18 #include <apt-pkg/fileutl.h> 
  26 // ArchiveCleaner::Go - Perform smart cleanup of the archive            /*{{{*/ 
  27 // --------------------------------------------------------------------- 
  28 /* Scan the directory for files to erase, we check the version information 
  29    against our database to see if it is interesting */ 
  30 bool pkgArchiveCleaner::Go(std::string Dir
,pkgCache 
&Cache
) 
  32    bool CleanInstalled 
= _config
->FindB("APT::Clean-Installed",true); 
  34    DIR *D 
= opendir(Dir
.c_str()); 
  36       return _error
->Errno("opendir",_("Unable to read %s"),Dir
.c_str()); 
  38    std::string StartDir 
= SafeGetCWD(); 
  39    if (chdir(Dir
.c_str()) != 0) 
  42       return _error
->Errno("chdir",_("Unable to change to %s"),Dir
.c_str()); 
  45    for (struct dirent 
*Dir 
= readdir(D
); Dir 
!= 0; Dir 
= readdir(D
)) 
  48       if (strcmp(Dir
->d_name
,"lock") == 0 || 
  49           strcmp(Dir
->d_name
,"partial") == 0 || 
  50           strcmp(Dir
->d_name
,".") == 0 || 
  51           strcmp(Dir
->d_name
,"..") == 0) 
  55       if (stat(Dir
->d_name
,&St
) != 0) 
  57          chdir(StartDir
.c_str()); 
  59          return _error
->Errno("stat",_("Unable to stat %s."),Dir
->d_name
); 
  62       // Grab the package name 
  63       const char *I 
= Dir
->d_name
; 
  64       for (; *I 
!= 0 && *I 
!= '_';I
++); 
  67       std::string Pkg 
= DeQuoteString(std::string(Dir
->d_name
,I
-Dir
->d_name
)); 
  70       const char *Start 
= I 
+ 1; 
  71       for (I 
= Start
; *I 
!= 0 && *I 
!= '_';I
++); 
  74       std::string Ver 
= DeQuoteString(std::string(Start
,I
-Start
)); 
  78       for (I 
= Start
; *I 
!= 0 && *I 
!= '.' ;I
++); 
  81       std::string 
const Arch 
= DeQuoteString(std::string(Start
,I
-Start
)); 
  83       if (APT::Configuration::checkArchitecture(Arch
) == false) 
  87       pkgCache::PkgIterator P 
= Cache
.FindPkg(Pkg
); 
  90          pkgCache::VerIterator V 
= P
.VersionList(); 
  91          for (; V
.end() == false; ++V
) 
  93             // See if we can fetch this version at all 
  94             bool IsFetchable 
= false; 
  95             for (pkgCache::VerFileIterator J 
= V
.FileList();  
  96                  J
.end() == false; ++J
) 
  98                if (CleanInstalled 
== true && 
  99                    (J
.File()->Flags 
& pkgCache::Flag::NotSource
) != 0) 
 105             // See if this verison matches the file 
 106             if (IsFetchable 
== true && Ver 
== V
.VerStr()) 
 110          // We found a match, keep the file 
 111          if (V
.end() == false) 
 115       Erase(Dir
->d_name
,Pkg
,Ver
,St
); 
 118    chdir(StartDir
.c_str());