[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#160743: Cleanup



Hi,

I agree with the idea that after a successful install/upgrade we want to
remove the downloaded
debs. There are setups (like pbuilder) that want to keep the cache files
but those seem to be
not the common case. Attached is a quick patch to implement the removal.
We can tweak
the name and the default for "Apt::Keep-Downloaded-Debs" of course :)
Test-case is missing
but will soon follow if there is agreement on this.

Cheers,
 Michael
diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc
index 74a2424..f7dde47 100644
--- a/apt-private/private-install.cc
+++ b/apt-private/private-install.cc
@@ -346,6 +346,18 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety)
       c0out << _("Note: This is done automatically and on purpose by dpkg.") << std::endl;
    }
 
+   // cleanup downloaded debs
+   if (_config->FindB("Apt::Keep-Downloaded-Debs", true) == false)
+   {
+      std::string const archivedir = _config->FindDir("Dir::Cache::archives");
+      for (auto I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); ++I)
+      {
+	 if (flNotFile((*I)->DestFile) != archivedir)
+	    continue;
+         RemoveFile("Keep-Downloaded-Debs=false", (*I)->DestFile);
+      }
+   }
+
    return true;
 }
 									/*}}}*/
diff --git a/debian/apt.cron.daily b/debian/apt.cron.daily
index d3c9e04..7e976a0 100644
--- a/debian/apt.cron.daily
+++ b/debian/apt.cron.daily
@@ -62,6 +62,9 @@
 #  APT::Periodic::AutocleanInterval "0";
 #  - Do "apt-get autoclean" every n-days (0=disable)
 #
+#  APT::Periodic::CleanInterval "0";
+#  - Do "apt-get clean" every n-days (0=disable)
+#
 #  APT::Periodic::Verbose "0";
 #  - Send report mail to root
 #      0:  no report             (or null string)
@@ -411,6 +414,9 @@ eval $(apt-config shell UnattendedUpgradeInterval APT::Periodic::Unattended-Upgr
 AutocleanInterval=0
 eval $(apt-config shell AutocleanInterval APT::Periodic::AutocleanInterval)
 
+CleanInterval=0
+eval $(apt-config shell CleanInterval APT::Periodic::CleanInterval)
+
 BackupArchiveInterval=0
 eval $(apt-config shell BackupArchiveInterval APT::Periodic::BackupArchiveInterval)
 
@@ -422,7 +428,8 @@ if [ $UpdateInterval -eq 0 ] &&
    [ $DownloadUpgradeableInterval -eq 0 ] &&
    [ $UnattendedUpgradeInterval -eq 0 ] &&
    [ $BackupArchiveInterval -eq 0 ] &&
-   [ $AutocleanInterval -eq 0 ]; then
+   [ $AutocleanInterval -eq 0 ] &&
+   [ $CleanInterval -eq 0 ]; then
 
     # check cache size
     check_size_constraints
@@ -498,6 +505,19 @@ else
     debug_echo "unattended-upgrade (not run)"
 fi
 
+# clean package archive
+CLEAN_STAMP=/var/lib/apt/periodic/clean-stamp
+if check_stamp $CLEAN_STAMP $CleanInterval; then
+    if  eval apt-get $XAPTOPT -y clean $XSTDERR; then
+	debug_echo "clean (success)."
+	update_stamp $CLEAN_STAMP
+    else
+	debug_echo "clean (error)"
+    fi
+else
+    debug_echo "clean (not run)"
+fi
+
 # autoclean package archive
 AUTOCLEAN_STAMP=/var/lib/apt/periodic/autoclean-stamp
 if check_stamp $AUTOCLEAN_STAMP $AutocleanInterval; then

Reply to: