Attached is a debdiff against 1.5.5 that introduce two new configuration directives (check_disk and min_disk) that implement the suggestion I made earlier of checking for a minimal amount of disk space before download from the archive. apt-cacher will fail with "503 Cache Full" if the available space is below the min_disk threshold. It will still check indices in the archive with HEAD when appropriate, and will still deliver files from the cache that have not expired, so it still remain somewhat useful even if disk is low.
This patch also introduce a new Depends on libfilesys-diskspace-perl. I am not sure if it should have been a Recommends or Suggests instead. Sorry I did not wrote the patch against 1.6.7, as I am using 1.5.5 right now and really need that one fixed. The patch is fairly trivial and should be easy to port.
diff -Nru apt-cacher-1.5.5/apt-cacher2 apt-cacher-1.5.5/apt-cacher2 --- apt-cacher-1.5.5/apt-cacher2 2007-10-03 03:53:41.000000000 -0400 +++ apt-cacher-1.5.5/apt-cacher2 2008-12-21 15:53:24.000000000 -0500 @@ -61,6 +61,8 @@ use Sys::Hostname; +use Filesys::DiskSpace; + # Include the library for the config file parser push @INC,'/usr/share/apt-cacher/'; require 'apt-cacher-lib.pl'; @@ -765,6 +767,17 @@ next REQUEST; } + # ensure we have a minimum of free disk space on the + # partition the cache reside on + if ($$cfg{check_disk} && $$cfg{min_disk}) { + unless ( &check_disk_space($$cfg{min_disk}) ) { + # bail out + writeerrorlog("Available disk space below treshold, not serving request"); + &sendrsp(503, "Cache full"); + next REQUEST; + } + } + # (re) download them unlink($cached_file, $cached_head, $complete_file, $notify_file); debug_message("file does not exist or so, creating it"); @@ -1173,6 +1186,20 @@ return time () + $$cfg{fetch_timeout}; # five minutes from now } +sub check_disk_space { + # determine if the file system the cache reside on meet disk space requirement + my $min = shift; + + # convert from M to 1K block + $min *= 1024; + + my @dfres = df $$cfg{cache_dir}; + + debug_message("Check disk, $dfres[3] k available, treshold $min k"); + + return $dfres[3] >= $min; +} + my $header_stored=0; my $tstart; diff -Nru /tmp/epqqc7l0GY/apt-cacher-1.5.5/apt-cacher.conf /tmp/iFV6Bc5lkk/apt-cacher-1.5.5/apt-cacher.conf --- apt-cacher-1.5.5/apt-cacher.conf 2007-10-01 09:41:58.000000000 -0400 +++ apt-cacher-1.5.5/apt-cacher.conf 2008-12-21 15:53:24.000000000 -0500 @@ -142,3 +142,10 @@ # Note that you need to specify all target servers in the allowed_locations # options if you make use of it. Also note that the paths should not overlap # each other. FTP access method not supported yet, maybe in the future. + +# Wheter or not to check for low disk space prior to fetching files from the +# archive. Below min_disk MB available on the file system where the cache +# reside on, apt-cacher do not try to fetch the file from the archive, send +# HTTP 500 to the client and bail out. +check_disk=0 +min_disk=10 diff -Nru /tmp/epqqc7l0GY/apt-cacher-1.5.5/apt-cacher-lib.pl /tmp/iFV6Bc5lkk/apt-cacher-1.5.5/apt-cacher-lib.pl --- apt-cacher-1.5.5/apt-cacher-lib.pl 2007-09-30 18:41:54.000000000 -0400 +++ apt-cacher-1.5.5/apt-cacher-lib.pl 2008-12-21 15:53:24.000000000 -0500 @@ -26,7 +26,9 @@ allowed_hosts_6 => '*', allowed_hosts => '*', limit => 0, - daemon_port => 3142 + daemon_port => 3142, + check_disk => 0, + min_disk => 10 ); ($config_file) = @_; diff -Nru /tmp/epqqc7l0GY/apt-cacher-1.5.5/debian/changelog /tmp/iFV6Bc5lkk/apt-cacher-1.5.5/debian/changelog --- apt-cacher-1.5.5/debian/changelog 2007-10-04 16:50:12.000000000 -0400 +++ apt-cacher-1.5.5/debian/changelog 2008-12-21 15:53:24.000000000 -0500 @@ -1,3 +1,10 @@ +apt-cacher (1.5.5-eg1) hardy; urgency=low + + * Added routine to check minimum disk space available for cache + LP: #291748 + + -- Etienne Goyer <etienne.go...@canonical.com> Sun, 21 Dec 2008 14:37:42 -0500 + apt-cacher (1.5.5) unstable; urgency=low * Make apt-cacher-report.pl more tolerant of logfile corruption. Thanks diff -Nru /tmp/epqqc7l0GY/apt-cacher-1.5.5/debian/control /tmp/iFV6Bc5lkk/apt-cacher-1.5.5/debian/control --- apt-cacher-1.5.5/debian/control 2007-09-28 17:42:22.000000000 -0400 +++ apt-cacher-1.5.5/debian/control 2008-12-21 15:53:24.000000000 -0500 @@ -9,7 +9,7 @@ Package: apt-cacher Architecture: all -Depends: ${perl:Depends}, bzip2, libwww-perl +Depends: ${perl:Depends}, bzip2, libwww-perl, libfilesys-diskspace-perl Suggests: libdbd-sqlite3-perl Description: Caching proxy for Debian package and source files Apt-cacher performs caching of .deb and source packages which have been
signature.asc
Description: OpenPGP digital signature