From bd7c126e3fb1b94e76e0e632c657cea854586844 Mon Sep 17 00:00:00 2001 From: Gábor Németh Date: Mon, 6 Mar 2023 16:19:14 +0100 Subject: Add 'dist-clean' command to remove packages and list files We assume all files in the 'listsdir' are candidates. Keep only files ending with Release, Release.gpg, and InRelease. Closes: #959093 --- apt-private/private-download.cc | 23 ++++++++++++++++++----- apt-private/private-download.h | 2 ++ 2 files changed, 20 insertions(+), 5 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-download.cc b/apt-private/private-download.cc index eddb901d0..b271ec03f 100644 --- a/apt-private/private-download.cc +++ b/apt-private/private-download.cc @@ -304,8 +304,19 @@ bool DoChangelog(CommandLine &CmdL) } /*}}}*/ -// DoClean - Remove download archives /*{{{*/ +// DoClean - Remove download archives /*{{{*/ bool DoClean(CommandLine &) +{ + return DoDistClean(false); +} + /*}}}*/ +// DoDistClean - Remove download archives and lists /*{{{*/ +bool DoDistClean(CommandLine &) +{ + return DoDistClean(true); +} +// DoDistClean - the worker +bool DoDistClean(bool ListsToo) { std::string const archivedir = _config->FindDir("Dir::Cache::archives"); std::string const listsdir = _config->FindDir("Dir::state::lists"); @@ -315,23 +326,25 @@ bool DoClean(CommandLine &) std::string const pkgcache = _config->FindFile("Dir::cache::pkgcache"); std::string const srcpkgcache = _config->FindFile("Dir::cache::srcpkgcache"); std::cout << "Del " << archivedir << "* " << archivedir << "partial/*"<< std::endl - << "Del " << listsdir << "partial/*" << std::endl - << "Del " << pkgcache << " " << srcpkgcache << std::endl; + << "Del " << listsdir << "partial/*" << (ListsToo ? " *_{Packages,Sources}{,.diff_Index}" : "") << std::endl + << "Del " << pkgcache << " " << srcpkgcache << std::endl; return true; } pkgAcquire Fetcher; if (archivedir.empty() == false && FileExists(archivedir) == true && - Fetcher.GetLock(archivedir) == true) + Fetcher.GetLock(archivedir) == true) { Fetcher.Clean(archivedir); Fetcher.Clean(archivedir + "partial/"); } if (listsdir.empty() == false && FileExists(listsdir) == true && - Fetcher.GetLock(listsdir) == true) + Fetcher.GetLock(listsdir) == true) { Fetcher.Clean(listsdir + "partial/"); + if (ListsToo) + Fetcher.CleanLists(listsdir); } pkgCacheFile::RemoveCaches(); diff --git a/apt-private/private-download.h b/apt-private/private-download.h index d829e8b24..918828241 100644 --- a/apt-private/private-download.h +++ b/apt-private/private-download.h @@ -33,6 +33,8 @@ APT_PUBLIC bool DoDownload(CommandLine &CmdL); APT_PUBLIC bool DoChangelog(CommandLine &CmdL); APT_PUBLIC bool DoClean(CommandLine &CmdL); +APT_PUBLIC bool DoDistClean(CommandLine &CmdL); +bool DoDistClean(bool ListsToo); APT_PUBLIC bool DoAutoClean(CommandLine &CmdL); #endif -- cgit v1.2.3-70-g09d2