On Tue, Oct 09, 2012 at 07:22:42PM +0200, Tobias Frost wrote:
> Hallo Mark,
> 
> I was able to pinpoint the problem but my perl knowledge is too limited
> to provide a fix.
> 
> In line 1642 of /usr/sbin/apt-cacher the check is done, and for that 
> $statfs->{used} + (new-content-file) is checked against the
> configuration. $statfs->{used} is set via df($cfg->{'cache_dir'}, 1)
> 
> However, http://search.cpan.org/~iguthrie/Filesys-Df-0.92/Df.pm
> tell however, that 
> "{used} = Total blocks used on the filesystem."
> and not the total blocks used in the given directory.

Well done! On all my systems /var/cache/apt-cacher is a separate 
partition so I had missed the bug.

Try this patch. I would be interested if you fine any performance hit. 
It is minimal here, but YMMV.

Mark


diff --git a/apt-cacher b/apt-cacher
index b3863aa..2a589b7 100755
--- a/apt-cacher
+++ b/apt-cacher
@@ -1583,6 +1583,17 @@ sub mapped_url_list {
     }
 }
 
+sub cache_size {
+    use File::Find qw();
+    my $ret;
+
+    File::Find::find({
+                     wanted => sub { $ret += -f $_ ? -s _ : 0 },
+                     preprocess => sub { grep {-r}  @_ } # skip non-readable
+                    }, $cfg->{'cache_dir'});
+    return $ret;
+}
+
 
 # runs the get or head operations on the user agent
 sub libcurl {
@@ -1645,7 +1656,7 @@ sub libcurl {
                                $response->header('Content-Length') &&
                                $response->header('Content-Length') >=  
$statfs->{bavail} ||
                                $cfg->{_disk_usage_limit} &&
-                               $statfs->{used} + 
$response->header('Content-Length') >= $cfg->{_disk_usage_limit}) {
+                               cache_size() + 
$response->header('Content-Length') >= $cfg->{_disk_usage_limit}) {
                                info_message('ALARM: Insuffient space for 
Content-Length: '.
                                             
$response->header('Content-Length').
                                             ' in cache_dir with ' . 
$statfs->{bavail} . ' available space');


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to