]>
git.saurik.com Git - apt.git/blob - apt-pkg/clean.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: clean.cc,v 1.3 1999/10/03 21:09:27 jgg Exp $
4 /* ######################################################################
6 Clean - Clean out downloaded directories
8 ##################################################################### */
12 #pragma implementation "apt-pkg/clean.h"
15 #include <apt-pkg/clean.h>
16 #include <apt-pkg/strutl.h>
17 #include <apt-pkg/error.h>
18 #include <apt-pkg/configuration.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 ",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)
55 return _error
->Errno("stat","Unable to stat %s.",Dir
->d_name
);
57 // Grab the package name
58 const char *I
= Dir
->d_name
;
59 for (; *I
!= 0 && *I
!= '_';I
++);
62 string Pkg
= DeQuoteString(string(Dir
->d_name
,I
-Dir
->d_name
));
65 const char *Start
= I
+ 1;
66 for (I
= Start
; *I
!= 0 && *I
!= '_';I
++);
69 string Ver
= DeQuoteString(string(Start
,I
-Start
));
73 for (I
= Start
; *I
!= 0 && *I
!= '.' ;I
++);
76 string Arch
= DeQuoteString(string(Start
,I
-Start
));
79 pkgCache::PkgIterator P
= Cache
.FindPkg(Pkg
);
82 pkgCache::VerIterator V
= P
.VersionList();
83 for (; V
.end() == false; V
++)
85 // See if we can fetch this version at all
86 bool IsFetchable
= false;
87 for (pkgCache::VerFileIterator J
= V
.FileList();
88 J
.end() == false; J
++)
90 if (CleanInstalled
== true &&
91 (J
.File()->Flags
& pkgCache::Flag::NotSource
) != 0)
97 // See if this verison matches the file
98 if (IsFetchable
== true && Ver
== V
.VerStr())
102 // We found a match, keep the file
103 if (V
.end() == false)
107 Erase(Dir
->d_name
,Pkg
,Ver
,St
);
110 chdir(StartDir
.c_str());