]>
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>
25 // ArchiveCleaner::Go - Perform smart cleanup of the archive /*{{{*/
26 // ---------------------------------------------------------------------
27 /* Scan the directory for files to erase, we check the version information
28 against our database to see if it is interesting */
29 bool pkgArchiveCleaner::Go(string Dir
,pkgCache
&Cache
)
31 bool CleanInstalled
= _config
->FindB("APT::Clean-Installed",true);
33 DIR *D
= opendir(Dir
.c_str());
35 return _error
->Errno("opendir",_("Unable to read %s"),Dir
.c_str());
37 string StartDir
= SafeGetCWD();
38 if (chdir(Dir
.c_str()) != 0)
41 return _error
->Errno("chdir",_("Unable to change to %s"),Dir
.c_str());
44 for (struct dirent
*Dir
= readdir(D
); Dir
!= 0; Dir
= readdir(D
))
47 if (strcmp(Dir
->d_name
,"lock") == 0 ||
48 strcmp(Dir
->d_name
,"partial") == 0 ||
49 strcmp(Dir
->d_name
,".") == 0 ||
50 strcmp(Dir
->d_name
,"..") == 0)
54 if (stat(Dir
->d_name
,&St
) != 0)
56 chdir(StartDir
.c_str());
58 return _error
->Errno("stat",_("Unable to stat %s."),Dir
->d_name
);
61 // Grab the package name
62 const char *I
= Dir
->d_name
;
63 for (; *I
!= 0 && *I
!= '_';I
++);
66 string Pkg
= DeQuoteString(string(Dir
->d_name
,I
-Dir
->d_name
));
69 const char *Start
= I
+ 1;
70 for (I
= Start
; *I
!= 0 && *I
!= '_';I
++);
73 string Ver
= DeQuoteString(string(Start
,I
-Start
));
77 for (I
= Start
; *I
!= 0 && *I
!= '.' ;I
++);
80 string
const Arch
= DeQuoteString(string(Start
,I
-Start
));
82 if (APT::Configuration::checkArchitecture(Arch
) == false)
86 pkgCache::PkgIterator P
= Cache
.FindPkg(Pkg
);
89 pkgCache::VerIterator V
= P
.VersionList();
90 for (; V
.end() == false; ++V
)
92 // See if we can fetch this version at all
93 bool IsFetchable
= false;
94 for (pkgCache::VerFileIterator J
= V
.FileList();
95 J
.end() == false; ++J
)
97 if (CleanInstalled
== true &&
98 (J
.File()->Flags
& pkgCache::Flag::NotSource
) != 0)
104 // See if this verison matches the file
105 if (IsFetchable
== true && Ver
== V
.VerStr())
109 // We found a match, keep the file
110 if (V
.end() == false)
114 Erase(Dir
->d_name
,Pkg
,Ver
,St
);
117 chdir(StartDir
.c_str());