summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Kalnischkies <kalnischkies@gmail.com>2012-02-11 22:36:03 +0100
committerDavid Kalnischkies <kalnischkies@gmail.com>2012-02-11 22:36:03 +0100
commitfbb2c7e04dd3155983560e0b01a71fd8f62f0b1b (patch)
tree638b2a0477372f5b36690dbc32da19488ed34ee0
parentf40db111e15e0d7bed3a6432d96c17553ee6f68e (diff)
* apt-pkg/cachefile.cc:
- clean up lost atomic cachefiles with 'clean' (Closes: #650513)
-rw-r--r--apt-pkg/cachefile.cc34
-rw-r--r--apt-pkg/contrib/fileutl.cc74
-rw-r--r--apt-pkg/contrib/fileutl.h1
-rw-r--r--debian/changelog4
4 files changed, 112 insertions, 1 deletions
diff --git a/apt-pkg/cachefile.cc b/apt-pkg/cachefile.cc
index 1b8d91a44..e425c940d 100644
--- a/apt-pkg/cachefile.cc
+++ b/apt-pkg/cachefile.cc
@@ -178,6 +178,40 @@ void pkgCacheFile::RemoveCaches()
unlink(pkgcache.c_str());
if (srcpkgcache.empty() == false && RealFileExists(srcpkgcache) == true)
unlink(srcpkgcache.c_str());
+ if (pkgcache.empty() == false)
+ {
+ std::string cachedir = flNotFile(pkgcache);
+ std::string cachefile = flNotDir(pkgcache);
+ if (cachedir.empty() != true && cachefile.empty() != true)
+ {
+ cachefile.append(".");
+ std::vector<std::string> caches = GetListOfFilesInDir(cachedir, false);
+ for (std::vector<std::string>::const_iterator file = caches.begin(); file != caches.end(); ++file)
+ {
+ std::string nuke = flNotDir(*file);
+ if (strncmp(cachefile.c_str(), nuke.c_str(), cachefile.length()) != 0)
+ continue;
+ unlink(file->c_str());
+ }
+ }
+ }
+
+ if (srcpkgcache.empty() == true)
+ return;
+
+ std::string cachedir = flNotFile(srcpkgcache);
+ std::string cachefile = flNotDir(srcpkgcache);
+ if (cachedir.empty() == true || cachefile.empty() == true)
+ return;
+ cachefile.append(".");
+ std::vector<std::string> caches = GetListOfFilesInDir(cachedir, false);
+ for (std::vector<std::string>::const_iterator file = caches.begin(); file != caches.end(); ++file)
+ {
+ std::string nuke = flNotDir(*file);
+ if (strncmp(cachefile.c_str(), nuke.c_str(), cachefile.length()) != 0)
+ continue;
+ unlink(file->c_str());
+ }
}
/*}}}*/
// CacheFile::Close - close the cache files /*{{{*/
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index 529e7d655..557ba0ca6 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -458,6 +458,80 @@ std::vector<string> GetListOfFilesInDir(string const &Dir, std::vector<string> c
std::sort(List.begin(),List.end());
return List;
}
+std::vector<string> GetListOfFilesInDir(string const &Dir, bool SortList)
+{
+ bool const Debug = _config->FindB("Debug::GetListOfFilesInDir", false);
+ if (Debug == true)
+ std::clog << "Accept in " << Dir << " all regular files" << std::endl;
+
+ std::vector<string> List;
+
+ if (DirectoryExists(Dir.c_str()) == false)
+ {
+ _error->Error(_("List of files can't be created as '%s' is not a directory"), Dir.c_str());
+ return List;
+ }
+
+ DIR *D = opendir(Dir.c_str());
+ if (D == 0)
+ {
+ _error->Errno("opendir",_("Unable to read %s"),Dir.c_str());
+ return List;
+ }
+
+ for (struct dirent *Ent = readdir(D); Ent != 0; Ent = readdir(D))
+ {
+ // skip "hidden" files
+ if (Ent->d_name[0] == '.')
+ continue;
+
+ // Make sure it is a file and not something else
+ string const File = flCombine(Dir,Ent->d_name);
+#ifdef _DIRENT_HAVE_D_TYPE
+ if (Ent->d_type != DT_REG)
+#endif
+ {
+ if (RealFileExists(File.c_str()) == false)
+ {
+ if (Debug == true)
+ std::clog << "Bad file: " << Ent->d_name << " → it is not a real file" << std::endl;
+ continue;
+ }
+ }
+
+ // Skip bad filenames ala run-parts
+ const char *C = Ent->d_name;
+ for (; *C != 0; ++C)
+ if (isalpha(*C) == 0 && isdigit(*C) == 0
+ && *C != '_' && *C != '-' && *C != '.')
+ break;
+
+ // we don't reach the end of the name -> bad character included
+ if (*C != 0)
+ {
+ if (Debug == true)
+ std::clog << "Bad file: " << Ent->d_name << " → bad character »" << *C << "« in filename" << std::endl;
+ continue;
+ }
+
+ // skip filenames which end with a period. These are never valid
+ if (*(C - 1) == '.')
+ {
+ if (Debug == true)
+ std::clog << "Bad file: " << Ent->d_name << " → Period as last character" << std::endl;
+ continue;
+ }
+
+ if (Debug == true)
+ std::clog << "Accept file: " << Ent->d_name << " in " << Dir << std::endl;
+ List.push_back(File);
+ }
+ closedir(D);
+
+ if (SortList == true)
+ std::sort(List.begin(),List.end());
+ return List;
+}
/*}}}*/
// SafeGetCWD - This is a safer getcwd that returns a dynamic string /*{{{*/
// ---------------------------------------------------------------------
diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h
index 3814cfe44..1ca41cb7d 100644
--- a/apt-pkg/contrib/fileutl.h
+++ b/apt-pkg/contrib/fileutl.h
@@ -171,6 +171,7 @@ std::vector<std::string> GetListOfFilesInDir(std::string const &Dir, std::string
bool const &SortList, bool const &AllowNoExt=false);
std::vector<std::string> GetListOfFilesInDir(std::string const &Dir, std::vector<std::string> const &Ext,
bool const &SortList);
+std::vector<std::string> GetListOfFilesInDir(std::string const &Dir, bool SortList);
std::string SafeGetCWD();
void SetCloseExec(int Fd,bool Close);
void SetNonBlock(int Fd,bool Block);
diff --git a/debian/changelog b/debian/changelog
index 0a366a6fb..6ef3c4a78 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -23,6 +23,8 @@ apt (0.8.16~exp13) UNRELEASED; urgency=low
* cmdline/apt-mark.cc:
- detect if dpkg has multiarch support before calling --set-selections
- correctly ignore already (un)hold packages
+ * apt-pkg/cachefile.cc:
+ - clean up lost atomic cachefiles with 'clean' (Closes: #650513)
[ Steve Langasek ]
* cmdline/apt-get.cc:
@@ -45,7 +47,7 @@ apt (0.8.16~exp13) UNRELEASED; urgency=low
* apt-pkg/contrib/fileutl.h:
- fix compat with FileFd::OpenDescriptor() in ReadOnlyGzip mode
- -- David Kalnischkies <kalnischkies@gmail.com> Sat, 11 Feb 2012 21:23:00 +0100
+ -- David Kalnischkies <kalnischkies@gmail.com> Sat, 11 Feb 2012 22:34:29 +0100
apt (0.8.16~exp12) experimental; urgency=low