Package: apt Version: 0.8.14.1 Severity: normal
I recently discovered the /etc/cron.daily/apt script and wanted to use it to download upgradeable packages and then immediately afterwards delete them. Point is: There's a caching daemon (apt-cacher-ng) in between that will keep requested packages around but cannot by itsself determine and download upgradeable packages. So, as suggested in the cron job, I created the file /etc/apt/apt.conf.d/02periodic with the following contents: APT::Periodic::MinAge "0"; APT::Periodic::Verbose "2"; APT::Periodic::MaxSize "1"; APT::Periodic::Update-Package-Lists "1"; APT::Periodic::Download-Upgradeable-Packages "1"; The MinAge=0 setting should allow the clean-by-size-routine to indiscriminately kill newly downloaded packages, or so I thought. Well, it doesn't, as this whole clean-by-size subtree will be deactivated if MinAge==0. This is easily fixed by moving this check a bit deeper as can be seen in the small and trivial patch I attached (apt.remove_by_size.diff). I don't think it'll break any of the more customary use cases (such as "actually keeping downloaded packages around for later installation" :). There are also a few comments marked TODO in this diff - those contain suggestions for later improvements (or silly remarks, I'm often not sure). Thanks, Hagen
diff --git a/cron.daily/apt b/cron.daily/apt index 75986f5..efce46f 100755 --- a/cron.daily/apt +++ b/cron.daily/apt @@ -170,6 +170,7 @@ check_size_constraints() # check size if [ ! $MaxSize -eq 0 ]; then # maxSize is in MB + # TODO Well, no... 1024 -> binary prefixes (MiB, KiB,... :). MaxSize=$(($MaxSize*1024)) #get current time @@ -187,7 +188,7 @@ check_size_constraints() fi # check for MinAge of the file - if [ $MinAge -ne 0 ]; then + # hfuchs| Moved age check deeper below - doesn't make sense here. # check both ctime and mtime mtime=$(stat -c %Y $file) ctime=$(stat -c %Z $file) @@ -196,14 +197,19 @@ check_size_constraints() else delta=$(($now-$ctime)) fi - if [ $delta -le $MinAge ]; then + # hfuchs| Moved MinAge != 0 check here. + if [ $delta -le $MinAge -a $MinAge -ne 0 ]; then debug_echo "skip remove by archive size: $file, delta=$delta < $MinAgeSec" + # TODO Why break here? Just because of one file that's too fresh? break else # delete oldest file + # TODO btw: I read somewhere at the top of this file that + # the biggest files are deleted first? I can't see it + # happening. Don't relly care, either. ;) + # TODO Indentation is a bit of a mess down here. debug_echo "remove by archive size: $file, delta=$delta >= $MinAgeSec (sec), size=$size >= $MaxSize" rm -f $file - fi fi done fi