Package: apt-cacher Version: 1.7.10 I believe I have found a bug in apt-cacher-import.pl which would result in its generating header files without a Content-Length header, which would then force the relevant packages to be redownloaded rather than served from the cache. The patch probably demonstrates the problem best:
diff -ur apt-cacher-1.7.10/apt-cacher-import.pl apt-cacher-hacked/apt-cacher-import.pl --- apt-cacher-1.7.10/apt-cacher-import.pl 2014-08-29 13:20:35.000000000 +0000 +++ apt-cacher-hacked/apt-cacher-import.pl 2015-04-08 08:36:03.535769331 +0000 @@ -334,7 +334,7 @@ write_header("$header_dir/$targetfile", HTTP::Response->new(200, 'OK', ['Date' => $headerdate, 'Last-Modified' => $headerdate, - 'Content-Length' => -s $packagefile])); + 'Content-Length' => -s "$package_dir/$targetfile"])); } # copy the ownership of the private directory At the time the header is written, $packagefile has already been moved by import_file to "$package_dir/$targetfile", so the original code would result in an undefined value rather than the package file's actual length being passed as an argument to HTTP::Response->new. The result is log file entries such as: Wed Apr 8 08:22:34 2015|debug [9398]: Processing a new request line Wed Apr 8 08:22:34 2015|debug [9398]: got: 'GET http://localhost:3143/ftp.debian.org/debian/pool/main/f/findutils/find utils_4.4.2-9%2bb1_amd64.deb HTTP/1.1' Wed Apr 8 08:22:34 2015|debug [9398]: Processing a new request line Wed Apr 8 08:22:34 2015|debug [9398]: got: 'Host: localhost:3143' Wed Apr 8 08:22:34 2015|debug [9398]: Processing a new request line Wed Apr 8 08:22:34 2015|debug [9398]: got: 'User-Agent: Debian APT-HTTP/1.3 (1.0.9.7)' Wed Apr 8 08:22:34 2015|debug [9398]: Processing a new request line Wed Apr 8 08:22:34 2015|debug [9398]: got: '' Wed Apr 8 08:22:34 2015|debug [9398]: Using cached result for host localhost:3143 in absolute URI Wed Apr 8 08:22:34 2015|debug [9398]: Host in Absolute URI is this server Wed Apr 8 08:22:34 2015|debug [9398]: Resolved request is http://ftp.debian.org/debian/pool/main/f/findutils/findutils _4.4.2-9+b1_amd64.deb Wed Apr 8 08:22:34 2015|debug [9398]: Testing URI: ftp.debian.org/debian/pool/main/f/findutils/findutils_4.4.2-9+b1_am d64.deb against ^ftp\.debian\.org/ Wed Apr 8 08:22:34 2015|debug [9398]: Package file: findutils_4.4.2-9+b1_amd64.deb Wed Apr 8 08:22:34 2015|debug [9398]: Locked header /var/cache/apt-cacher/headers/findutils_4.4.2-9+b1_amd64.deb Wed Apr 8 08:22:34 2015|debug [9398]: Complete check Wed Apr 8 08:22:34 2015|info [9398]: Warning: failed to read cached Content-Length Wed Apr 8 08:22:34 2015|debug [9398]: Deleting /var/cache/apt-cacher/headers/findutils_4.4.2-9+b1_amd64.deb Wed Apr 8 08:22:34 2015|debug [9398]: Deleting /var/cache/apt-cacher/packages/findutils_4.4.2-9+b1_amd64.deb Wed Apr 8 08:22:34 2015|debug [9398]: Locked header /var/cache/apt-cacher/headers/findutils_4.4.2-9+b1_amd64.deb Wed Apr 8 08:22:34 2015|debug [9398]: file does not exist or download required Wed Apr 8 08:22:34 2015|debug [9398]: MISS (Using debug = 7. Please note that I have moved apt-cacher to port 3143; that is not the bug). Applying the patch results in the expected behavior; imported packages are properly served from the cache and no longer downloaded over the net. I hope this email arrives in a readable format; reportbug, unfortunately, failed to run for me.
diff -ur apt-cacher-1.7.10/apt-cacher-import.pl apt-cacher-hacked/apt-cacher-import.pl --- apt-cacher-1.7.10/apt-cacher-import.pl 2014-08-29 13:20:35.000000000 +0000 +++ apt-cacher-hacked/apt-cacher-import.pl 2015-04-08 08:36:03.535769331 +0000 @@ -334,7 +334,7 @@ write_header("$header_dir/$targetfile", HTTP::Response->new(200, 'OK', ['Date' => $headerdate, 'Last-Modified' => $headerdate, - 'Content-Length' => -s $packagefile])); + 'Content-Length' => -s "$package_dir/$targetfile"])); } # copy the ownership of the private directory