]>
git.saurik.com Git - apt.git/blob - apt-pkg/clean.cc
0ee3b765d4ebf49c292b41c8f8b568e41b82c238
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>
19 #include <apt-pkg/pkgcache.h>
20 #include <apt-pkg/cacheiterators.h>
30 // ArchiveCleaner::Go - Perform smart cleanup of the archive /*{{{*/
31 // ---------------------------------------------------------------------
32 /* Scan the directory for files to erase, we check the version information
33 against our database to see if it is interesting */
34 bool pkgArchiveCleaner::Go(std::string Dir
,pkgCache
&Cache
)
36 bool CleanInstalled
= _config
->FindB("APT::Clean-Installed",true);
38 DIR *D
= opendir(Dir
.c_str());
40 return _error
->Errno("opendir",_("Unable to read %s"),Dir
.c_str());
42 std::string StartDir
= SafeGetCWD();
43 if (chdir(Dir
.c_str()) != 0)
46 return _error
->Errno("chdir",_("Unable to change to %s"),Dir
.c_str());
49 for (struct dirent
*Dir
= readdir(D
); Dir
!= 0; Dir
= readdir(D
))
52 if (strcmp(Dir
->d_name
,"lock") == 0 ||
53 strcmp(Dir
->d_name
,"partial") == 0 ||
54 strcmp(Dir
->d_name
,".") == 0 ||
55 strcmp(Dir
->d_name
,"..") == 0)
59 if (stat(Dir
->d_name
,&St
) != 0)
61 _error
->Errno("stat",_("Unable to stat %s."),Dir
->d_name
);
63 if (chdir(StartDir
.c_str()) != 0)
64 return _error
->Errno("chdir", _("Unable to change to %s"), StartDir
.c_str());
68 // Grab the package name
69 const char *I
= Dir
->d_name
;
70 for (; *I
!= 0 && *I
!= '_';I
++);
73 std::string Pkg
= DeQuoteString(std::string(Dir
->d_name
,I
-Dir
->d_name
));
76 const char *Start
= I
+ 1;
77 for (I
= Start
; *I
!= 0 && *I
!= '_';I
++);
80 std::string Ver
= DeQuoteString(std::string(Start
,I
-Start
));
84 for (I
= Start
; *I
!= 0 && *I
!= '.' ;I
++);
87 std::string
const Arch
= DeQuoteString(std::string(Start
,I
-Start
));
89 // ignore packages of unconfigured architectures
90 if (APT::Configuration::checkArchitecture(Arch
) == false)
94 pkgCache::PkgIterator P
= Cache
.FindPkg(Pkg
, Arch
);
97 pkgCache::VerIterator V
= P
.VersionList();
98 for (; V
.end() == false; ++V
)
100 // See if we can fetch this version at all
101 bool IsFetchable
= false;
102 for (pkgCache::VerFileIterator J
= V
.FileList();
103 J
.end() == false; ++J
)
105 if (CleanInstalled
== true &&
106 (J
.File()->Flags
& pkgCache::Flag::NotSource
) != 0)
112 // See if this version matches the file
113 if (IsFetchable
== true && Ver
== V
.VerStr())
117 // We found a match, keep the file
118 if (V
.end() == false)
122 Erase(Dir
->d_name
,Pkg
,Ver
,St
);
126 if (chdir(StartDir
.c_str()) != 0)
127 return _error
->Errno("chdir", _("Unable to change to %s"), StartDir
.c_str());