]>
git.saurik.com Git - apt.git/blob - apt-pkg/clean.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: clean.cc,v 1.2 1999/06/24 04:06:30 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>
24 // ArchiveCleaner::Go - Perform smart cleanup of the archive /*{{{*/
25 // ---------------------------------------------------------------------
26 /* Scan the directory for files to erase, we check the version information
27 against our database to see if it is interesting */
28 bool pkgArchiveCleaner::Go(string Dir
,pkgCache
&Cache
)
30 DIR *D
= opendir(Dir
.c_str());
32 return _error
->Errno("opendir","Unable to read %s",Dir
.c_str());
34 string StartDir
= SafeGetCWD();
35 if (chdir(Dir
.c_str()) != 0)
38 return _error
->Errno("chdir","Unable to change to ",Dir
.c_str());
41 for (struct dirent
*Dir
= readdir(D
); Dir
!= 0; Dir
= readdir(D
))
44 if (strcmp(Dir
->d_name
,"lock") == 0 ||
45 strcmp(Dir
->d_name
,"partial") == 0 ||
46 strcmp(Dir
->d_name
,".") == 0 ||
47 strcmp(Dir
->d_name
,"..") == 0)
51 if (stat(Dir
->d_name
,&St
) != 0)
52 return _error
->Errno("stat","Unable to stat %s.",Dir
->d_name
);
54 // Grab the package name
55 const char *I
= Dir
->d_name
;
56 for (; *I
!= 0 && *I
!= '_';I
++);
59 string Pkg
= DeQuoteString(string(Dir
->d_name
,I
-Dir
->d_name
));
62 const char *Start
= I
+ 1;
63 for (I
= Start
; *I
!= 0 && *I
!= '_';I
++);
66 string Ver
= DeQuoteString(string(Start
,I
-Start
));
70 for (I
= Start
; *I
!= 0 && *I
!= '.' ;I
++);
73 string Arch
= DeQuoteString(string(Start
,I
-Start
));
76 pkgCache::PkgIterator P
= Cache
.FindPkg(Pkg
);
79 pkgCache::VerIterator V
= P
.VersionList();
80 for (; V
.end() == false; V
++)
82 // See if we can fetch this version at all
83 bool IsFetchable
= false;
84 for (pkgCache::VerFileIterator J
= V
.FileList();
85 J
.end() == false; J
++)
87 if ((J
.File()->Flags
& pkgCache::Flag::NotSource
) != 0)
93 // See if this verison matches the file
94 if (IsFetchable
== true && Ver
== V
.VerStr())
98 // We found a match, keep the file
103 Erase(Dir
->d_name
,Pkg
,Ver
,St
);
106 chdir(StartDir
.c_str());