Bug#625845: apt cron cleanse logic borked
Hi there,
the apt cron script had borked math checks in it, astonished noone
notices and fixed it before. With attached patch, it actually cleans the
cached packages archive as it is supposed to.
#happy new year & regards!marcel C:
--- cron.daily/apt.orig 2011-10-14 13:48:06.000000000 +0200
+++ cron.daily/apt 2011-12-25 23:26:13.560399973 +0100
@@ -27,12 +27,12 @@
# - Set periodic package backup directory
#
# APT::Archives::MaxAge "0"; (old, deprecated)
-# APT::Periodic::MaxAge "0"; (new)
+# APT::Periodic::MaxAge "0"; (new, in days)
# - Set maximum allowed age of a cache package file. If a cache
# package file is older it is deleted (0=disable)
#
# APT::Archives::MinAge "2"; (old, deprecated)
-# APT::Periodic::MinAge "2"; (new)
+# APT::Periodic::MinAge "2"; (new, in days)
# - Set minimum age of a package file. If a file is younger it
# will not be deleted (0=disable). Usefull to prevent races
# and to keep backups of the packages for emergency.
@@ -173,11 +173,11 @@
MaxSize=$(($MaxSize*1024))
#get current time
- now=$(date --date=$(date --iso-8601) +%s)
- MinAge=$(($MinAge*24*60*60))
+ now=$(date +%s)
+ MinAgeSec=$(($MinAge*24*60*60))
- # reverse-sort by mtime
- for file in $(ls -rt $Cache/*.deb 2>/dev/null); do
+ # reverse-sort by ctime
+ for file in $(ls -crt $Cache/*.deb 2>/dev/null); do
du=$(du -s $Cache)
size=${du%%/*}
# check if the cache is small enough
@@ -187,7 +187,7 @@
fi
# check for MinAge of the file
- if [ $MinAge -ne 0 ]; then
+ if [ $MinAgeSec -ne 0 ]; then
# check both ctime and mtime
mtime=$(stat -c %Y $file)
ctime=$(stat -c %Z $file)
@@ -196,15 +196,14 @@
else
delta=$(($now-$ctime))
fi
- if [ $delta -le $MinAge ]; then
+ if [ $delta -le $MinAgeSec ]; then
debug_echo "skip remove by archive size: $file, delta=$delta < $MinAgeSec"
break
- else
- # delete oldest file
- debug_echo "remove by archive size: $file, delta=$delta >= $MinAgeSec (sec), size=$size >= $MaxSize"
- rm -f $file
fi
fi
+ # delete oldest file
+ debug_echo "remove by archive size: $file, delta=$delta >= $MinAgeSec (sec), size=$size >= $MaxSize"
+ rm -f $file
done
fi
}
Reply to: