summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/acquire-item.cc4
-rw-r--r--apt-pkg/clean.cc111
-rw-r--r--apt-pkg/clean.h30
-rw-r--r--apt-pkg/contrib/strutl.cc28
-rw-r--r--apt-pkg/contrib/strutl.h3
-rw-r--r--apt-pkg/makefile6
6 files changed, 174 insertions, 8 deletions
diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc
index beb4260ac..ebef611d8 100644
--- a/apt-pkg/acquire-item.cc
+++ b/apt-pkg/acquire-item.cc
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: acquire-item.cc,v 1.22 1999/02/01 02:22:11 jgg Exp $
+// $Id: acquire-item.cc,v 1.23 1999/02/01 08:11:57 jgg Exp $
/* ######################################################################
Acquire Item - Item to acquire
@@ -363,7 +363,7 @@ pkgAcqArchive::pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
// Generate the final file name as: package_version_arch.deb
StoreFilename = QuoteString(Version.ParentPkg().Name(),"_:") + '_' +
QuoteString(Version.VerStr(),"_:") + '_' +
- QuoteString(Version.Arch(),"_:") + ".deb";
+ QuoteString(Version.Arch(),"_:.") + ".deb";
// Select a source
if (QueueNext() == false && _error->PendingError() == false)
diff --git a/apt-pkg/clean.cc b/apt-pkg/clean.cc
new file mode 100644
index 000000000..db47b1cc4
--- /dev/null
+++ b/apt-pkg/clean.cc
@@ -0,0 +1,111 @@
+// -*- mode: cpp; mode: fold -*-
+// Description /*{{{*/
+// $Id: clean.cc,v 1.1 1999/02/01 08:11:57 jgg Exp $
+/* ######################################################################
+
+ Clean - Clean out downloaded directories
+
+ ##################################################################### */
+ /*}}}*/
+// Includes /*{{{*/
+#ifdef __GNUG__
+#pragma implementation "apt-pkg/clean.h"
+#endif
+
+#include <apt-pkg/clean.h>
+#include <apt-pkg/strutl.h>
+#include <apt-pkg/error.h>
+
+#include <dirent.h>
+#include <sys/stat.h>
+#include <unistd.h>
+ /*}}}*/
+
+// ArchiveCleaner::Go - Perform smart cleanup of the archive /*{{{*/
+// ---------------------------------------------------------------------
+/* Scan the directory for files to erase, we check the version information
+ against our database to see if it is interesting */
+bool pkgArchiveCleaner::Go(string Dir,pkgCache &Cache)
+{
+ DIR *D = opendir(Dir.c_str());
+ if (D == 0)
+ return _error->Errno("opendir","Unable to read %s",Dir.c_str());
+
+ string StartDir = SafeGetCWD();
+ if (chdir(Dir.c_str()) != 0)
+ {
+ closedir(D);
+ return _error->Errno("chdir","Unable to change to ",Dir.c_str());
+ }
+
+ for (struct dirent *Dir = readdir(D); Dir != 0; Dir = readdir(D))
+ {
+ // Skip some files..
+ if (strcmp(Dir->d_name,"lock") == 0 ||
+ strcmp(Dir->d_name,"partial") == 0 ||
+ strcmp(Dir->d_name,".") == 0 ||
+ strcmp(Dir->d_name,"..") == 0)
+ continue;
+
+ struct stat St;
+ if (stat(Dir->d_name,&St) != 0)
+ return _error->Errno("stat","Unable to stat %s.",Dir->d_name);
+
+ // Grab the package name
+ const char *I = Dir->d_name;
+ for (; *I != 0 && *I != '_';I++);
+ if (*I != '_')
+ continue;
+ string Pkg = DeQuoteString(string(Dir->d_name,I-Dir->d_name));
+
+ // Grab the version
+ const char *Start = I + 1;
+ for (I = Start; *I != 0 && *I != '_';I++);
+ if (*I != '_')
+ continue;
+ string Ver = DeQuoteString(string(Start,I-Start));
+
+ // Grab the arch
+ Start = I + 1;
+ for (I = Start; *I != 0 && *I != '.' ;I++);
+ if (*I != '.')
+ continue;
+ string Arch = DeQuoteString(string(Start,I-Start));
+
+ // Lookup the package
+ pkgCache::PkgIterator P = Cache.FindPkg(Pkg);
+ if (P.end() != true)
+ {
+ pkgCache::VerIterator V = P.VersionList();
+ for (; V.end() == false; V++)
+ {
+ // See if we can fetch this version at all
+ bool IsFetchable = false;
+ for (pkgCache::VerFileIterator J = V.FileList();
+ J.end() == false; J++)
+ {
+ if ((J.File()->Flags & pkgCache::Flag::NotSource) != 0)
+ continue;
+ IsFetchable = true;
+ break;
+ }
+
+ // See if this verison matches the file
+ if (IsFetchable == true && Ver == V.VerStr())
+ break;
+ }
+
+ // We found a match, keep the file
+ if (V.end() == false)
+ continue;
+ }
+
+ Erase(Dir->d_name,Pkg,Ver,St);
+ unlink(Dir->d_name);
+ };
+
+ chdir(StartDir.c_str());
+ closedir(D);
+ return true;
+}
+ /*}}}*/
diff --git a/apt-pkg/clean.h b/apt-pkg/clean.h
new file mode 100644
index 000000000..afb5aa4f5
--- /dev/null
+++ b/apt-pkg/clean.h
@@ -0,0 +1,30 @@
+// -*- mode: cpp; mode: fold -*-
+// Description /*{{{*/
+// $Id: clean.h,v 1.1 1999/02/01 08:11:57 jgg Exp $
+/* ######################################################################
+
+ Clean - Clean out downloaded directories
+
+ ##################################################################### */
+ /*}}}*/
+#ifndef APTPKG_CLEAN_H
+#define APTPKG_CLEAN_H
+
+#ifdef __GNUG__
+#pragma interface "apt-pkg/clean.h"
+#endif
+
+#include <apt-pkg/pkgcache.h>
+
+class pkgArchiveCleaner
+{
+ protected:
+
+ virtual void Erase(const char *File,string Pkg,string Ver,struct stat &St) {};
+
+ public:
+
+ bool Go(string Dir,pkgCache &Cache);
+};
+
+#endif
diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc
index e0188e3b8..b5086be04 100644
--- a/apt-pkg/contrib/strutl.cc
+++ b/apt-pkg/contrib/strutl.cc
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: strutl.cc,v 1.18 1999/01/27 02:48:52 jgg Exp $
+// $Id: strutl.cc,v 1.19 1999/02/01 08:11:57 jgg Exp $
/* ######################################################################
String Util - Some usefull string functions.
@@ -116,7 +116,7 @@ bool ParseQuoteWord(const char *&String,string &Res)
{
Tmp[0] = Start[1];
Tmp[1] = Start[2];
- Tmp[3] = 0;
+ Tmp[2] = 0;
*I = (char)strtol(Tmp,0,16);
Start += 3;
continue;
@@ -177,6 +177,30 @@ bool ParseCWord(const char *String,string &Res)
return true;
}
/*}}}*/
+// DeQuoteString - Convert a string from quoted from /*{{{*/
+// ---------------------------------------------------------------------
+/* This undoes QuoteString */
+string DeQuoteString(string Str)
+{
+ string Res;
+ for (string::iterator I = Str.begin(); I != Str.end(); I++)
+ {
+ if (*I == '%' && I + 2 < Str.end())
+ {
+ char Tmp[3];
+ Tmp[0] = I[1];
+ Tmp[1] = I[2];
+ Tmp[2] = 0;
+ Res += (char)strtol(Tmp,0,16);
+ I += 2;
+ continue;
+ }
+ else
+ Res += *I;
+ }
+ return Res;
+}
+ /*}}}*/
// QuoteString - Convert a string into quoted from /*{{{*/
// ---------------------------------------------------------------------
/* */
diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h
index e9a31f144..a79f28e4e 100644
--- a/apt-pkg/contrib/strutl.h
+++ b/apt-pkg/contrib/strutl.h
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: strutl.h,v 1.11 1999/01/27 02:48:53 jgg Exp $
+// $Id: strutl.h,v 1.12 1999/02/01 08:11:57 jgg Exp $
/* ######################################################################
String Util - These are some usefull string functions
@@ -30,6 +30,7 @@ char *_strtabexpand(char *String,size_t Len);
bool ParseQuoteWord(const char *&String,string &Res);
bool ParseCWord(const char *String,string &Res);
string QuoteString(string Str,const char *Bad);
+string DeQuoteString(string Str);
string SizeToStr(double Bytes);
string TimeToStr(unsigned long Sec);
string SubstVar(string Str,string Subst,string Contents);
diff --git a/apt-pkg/makefile b/apt-pkg/makefile
index 08b8b2941..87a5e46f6 100644
--- a/apt-pkg/makefile
+++ b/apt-pkg/makefile
@@ -24,9 +24,9 @@ SOURCE = contrib/mmap.cc contrib/error.cc contrib/strutl.cc \
SOURCE+= pkgcache.cc version.cc fileutl.cc pkgcachegen.cc depcache.cc \
orderlist.cc tagfile.cc sourcelist.cc packagemanager.cc \
pkgrecords.cc algorithms.cc acquire.cc acquire-item.cc \
- acquire-worker.cc acquire-method.cc init.cc templates.cc
+ acquire-worker.cc acquire-method.cc init.cc clean.cc templates.cc
-# Source code for the debian specific components
+# Source code for the debian specific components
SOURCE+= deb/deblistparser.cc deb/debrecords.cc deb/dpkgpm.cc deb/dpkginit.cc
# Public apt-pkg header files
@@ -35,7 +35,7 @@ HEADERS = algorithms.h depcache.h mmap.h pkgcachegen.h cacheiterators.h \
packagemanager.h tagfile.h deblistparser.h init.h pkgcache.h \
version.h progress.h pkgrecords.h debrecords.h cmndline.h \
acquire.h acquire-worker.h acquire-item.h acquire-method.h md5.h \
- dpkgpm.h dpkginit.h cdromutl.h strutl.h
+ dpkgpm.h dpkginit.h cdromutl.h strutl.h clean.h
HEADERS := $(addprefix apt-pkg/,$(HEADERS))