]>
git.saurik.com Git - apt.git/blob - apt-pkg/clean.cc
629afd7cf2a7849e4b8ff2798a39698e5a0c7019
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 ##################################################################### */
11 #include <apt-pkg/clean.h>
12 #include <apt-pkg/strutl.h>
13 #include <apt-pkg/error.h>
14 #include <apt-pkg/configuration.h>
15 #include <apt-pkg/aptconfiguration.h>
23 // ArchiveCleaner::Go - Perform smart cleanup of the archive /*{{{*/
24 // ---------------------------------------------------------------------
25 /* Scan the directory for files to erase, we check the version information
26 against our database to see if it is interesting */
27 bool pkgArchiveCleaner::Go(string Dir
,pkgCache
&Cache
)
29 bool CleanInstalled
= _config
->FindB("APT::Clean-Installed",true);
31 DIR *D
= opendir(Dir
.c_str());
33 return _error
->Errno("opendir",_("Unable to read %s"),Dir
.c_str());
35 string StartDir
= SafeGetCWD();
36 if (chdir(Dir
.c_str()) != 0)
39 return _error
->Errno("chdir",_("Unable to change to %s"),Dir
.c_str());
42 for (struct dirent
*Dir
= readdir(D
); Dir
!= 0; Dir
= readdir(D
))
45 if (strcmp(Dir
->d_name
,"lock") == 0 ||
46 strcmp(Dir
->d_name
,"partial") == 0 ||
47 strcmp(Dir
->d_name
,".") == 0 ||
48 strcmp(Dir
->d_name
,"..") == 0)
52 if (stat(Dir
->d_name
,&St
) != 0)
54 chdir(StartDir
.c_str());
56 return _error
->Errno("stat",_("Unable to stat %s."),Dir
->d_name
);
59 // Grab the package name
60 const char *I
= Dir
->d_name
;
61 for (; *I
!= 0 && *I
!= '_';I
++);
64 string Pkg
= DeQuoteString(string(Dir
->d_name
,I
-Dir
->d_name
));
67 const char *Start
= I
+ 1;
68 for (I
= Start
; *I
!= 0 && *I
!= '_';I
++);
71 string Ver
= DeQuoteString(string(Start
,I
-Start
));
75 for (I
= Start
; *I
!= 0 && *I
!= '.' ;I
++);
78 string
const Arch
= DeQuoteString(string(Start
,I
-Start
));
80 if (APT::Configuration::checkArchitecture(Arch
) == false)
84 pkgCache::PkgIterator P
= Cache
.FindPkg(Pkg
);
87 pkgCache::VerIterator V
= P
.VersionList();
88 for (; V
.end() == false; V
++)
90 // See if we can fetch this version at all
91 bool IsFetchable
= false;
92 for (pkgCache::VerFileIterator J
= V
.FileList();
93 J
.end() == false; J
++)
95 if (CleanInstalled
== true &&
96 (J
.File()->Flags
& pkgCache::Flag::NotSource
) != 0)
102 // See if this verison matches the file
103 if (IsFetchable
== true && Ver
== V
.VerStr())
107 // We found a match, keep the file
108 if (V
.end() == false)
112 Erase(Dir
->d_name
,Pkg
,Ver
,St
);
115 chdir(StartDir
.c_str());