diff -Nru apt-cacher-1.7.6/apt-cacher apt-cacher-1.7.8/apt-cacher --- apt-cacher-1.7.6/apt-cacher 2012-10-03 07:21:42.000000000 +0000 +++ apt-cacher-1.7.8/apt-cacher 2013-10-21 15:41:35.000000000 +0000 @@ -528,7 +528,7 @@ else { undef $response; } - } while ($request == 1) || # get_request() failed but retry OK + } while (defined $request && $request == 1) || # get_request() failed but retry OK ($response && lc $response->header('Connection') eq 'keep-alive'); return; @@ -750,25 +750,26 @@ } # Send If-modified-since request for http, https or proxy request elsif (($request->uri->scheme =~ /https?/ || $cfg->{use_proxy}) && - (my $since = $cached_response->header('Last-Modified'))){ + (my $since = $cached_response->header('Last-Modified') || $cached_response->header('Date'))){ $cfg->{debug} && debug_message('Sending If-Modified-Since request'); my $ifmod_request = upstream_request($request); $ifmod_request->header('If-Modified-Since' => $since); $response = fetch_store($ifmod_request, $cache); $cfg->{debug} && debug_message('Got '.$response->code); - if ($response->code == 200) { - $cache->{status} = 'EXPIRED'; - $cfg->{debug} && debug_message($cache->{status}); - } - elsif ($response->code == 304) { + if ($response->code == 304) { # Update cached Date and Client-Date headers $cached_response->date($response->date || time); write_header($cache->{header}, $cached_response); } - elsif ($response->is_error) { + elsif (HTTP::Status::is_server_error($response->code)) { # Offline, used cached $cache->{status} = 'OFFLINE'; } + else { # Success or client error + $cache->{status} = 'EXPIRED'; + $cfg->{debug} && debug_message($cache->{status}); + } + } # Still don't know what to do? # use HTTP timestamping/ETag @@ -810,6 +811,11 @@ $cfg->{debug} && debug_message($cache->{status}); } } + else { + $cfg->{debug} && debug_message("downloading $cache->{name} because no validation tag found in cached response"); + $cache->{status} = 'EXPIRED'; + $cfg->{debug} && debug_message($cache->{status}); + } } else { $cfg->{debug} && debug_message('Validation failed: reusing existing file'); @@ -909,11 +915,7 @@ $response->remove_header('Connection'); } - my $ret = return_file ($response, $cache); - if ($ret && $ret==2) { # retry code - $cfg->{debug} && debug_message('return_file requested retry'); - goto complete_check; - } + return_file ($response, $cache); $cfg->{debug} && debug_message('Package sent'); # Write all the stuff to the log file @@ -1205,10 +1207,10 @@ print STDERR "$message\n"; # Better than nothing return; } - _flock($erlog_fh, LOCK_EX); + flock($erlog_fh, LOCK_EX); seek($erlog_fh, 0, 2); # Reset EOF to SEEK_END print $erlog_fh "$time|$message\n"; - _flock($erlog_fh, LOCK_UN); + flock($erlog_fh, LOCK_UN); return; } @@ -1581,6 +1583,31 @@ } } +sub cache_size { + use File::Find qw(); + use IPC::Shareable qw(); + use IPC::SysV qw(); + + tie my %du, 'IPC::Shareable', { key => IPC::SysV::ftok($cfg->{'cache_dir'}, 1), + create => 1}; + + # Sliding scale from 0 to 20 seconds + if (($du{'last_time'}||0) + + (20 * ($cfg->{'_disk_usage_limit'} - ($du{'size'}||0)) / $cfg->{'_disk_usage_limit'}) < + (my $time = time) and + (tied %du)->shlock(LOCK_EX|LOCK_NB)) { + $du{'size'}=0; + File::Find::find({ + wanted => sub { $du{'size'} += -f $_ ? -s _ : 0 }, + preprocess => sub { grep {-r} @_ } # skip non-readable + }, $cfg->{'cache_dir'}); + $du{'last_time'} = $time; + (tied %du)->shunlock; + debug_message("Cache Size: $du{'size'}"); + } + return $du{'size'}; +} + # runs the get or head operations on the user agent sub libcurl { @@ -1643,7 +1670,7 @@ $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'); @@ -1735,7 +1762,7 @@ elsif ($curl_request->method eq 'POST') { $response->add_content($_); } - elsif ($cache->{content}) { + elsif ($response->is_success && $cache->{content}) { print({$cache->{content}} $_) || do { # Don't use die to avoid invoking die handler info_message "Warning: print failed: $!"; @@ -1850,9 +1877,9 @@ if ($response->is_success) { write_header($cache->{header}, $response); } - elsif (!$request->header('If-Modified-Since')) { + elsif (HTTP::Status::is_client_error($response->code) || !$request->header('If-Modified-Since')) { # Not for If-Modified-Since requests to prevent deleting valid cached - # files after temporary errors + # files after temporary server errors $cfg->{debug} && debug_message('Unlinking cached files'); unlink_by_fh($cache->{header}, $cache->{content}); } diff -Nru apt-cacher-1.7.6/apt-cacher-cleanup.pl apt-cacher-1.7.8/apt-cacher-cleanup.pl --- apt-cacher-1.7.6/apt-cacher-cleanup.pl 2012-10-03 07:21:42.000000000 +0000 +++ apt-cacher-1.7.8/apt-cacher-cleanup.pl 2013-10-21 15:41:35.000000000 +0000 @@ -393,7 +393,7 @@ fcntl($tfh, F_SETFD, 0) or die "Can't clear close-on-exec flag on temp filehandle: $!\n"; my $cwd = Cwd::cwd(); # Save - chdir '/dev/fd' or die "Unable to change working directory: $!"; + chdir '/proc/self/fd' or die "Unable to change working directory: $!"; open(my $patchpipe, '|-', "$patchprog ".fileno($tfh)) || die "Unable to open pipe for patch: $!"; printmsg "Patching $name with $patchprog\n"; print $patchpipe $diffs; diff -Nru apt-cacher-1.7.6/apt-cacher-precache.pl apt-cacher-1.7.8/apt-cacher-precache.pl --- apt-cacher-1.7.6/apt-cacher-precache.pl 2012-03-06 11:30:04.000000000 +0000 +++ apt-cacher-1.7.8/apt-cacher-precache.pl 2013-02-03 12:15:07.000000000 +0000 @@ -75,9 +75,10 @@ You can feed existing package lists or old apt-cacher logs into the selection algorithm by using the -l option above. If the version is omited (eg. for lists created with \"dpkg --get-selections\" then the packages may be redownloaded). -To avoid this, use following one-liner to fake a list with version infos: +To avoid this, install libdpkg-perl and use following one-liner to fake a list +with version infos: -dpkg -l | perl -ne 'if(/^(i.|.i)\\s+(\\S+)\\s+(\\S+)/) { print \"\$2_\$3_i386.deb\\n\$2_\$3_all.deb\\n\"}' +dpkg -l | perl -MDpkg::Arch -ne 'if(/^(i.|.i)\\s+(\\S+)\\s+(\\S+)/) { print \"\$2_\$3_\", Dpkg::Arch::get_host_arch, \".deb\\n\$2_\$3_all.deb\\n\"}' "; exit 1;}; diff -Nru apt-cacher-1.7.6/debian/README.Debian apt-cacher-1.7.8/debian/README.Debian --- apt-cacher-1.7.6/debian/README.Debian 2012-10-03 07:21:42.000000000 +0000 +++ apt-cacher-1.7.8/debian/README.Debian 2013-10-21 15:41:35.000000000 +0000 @@ -10,7 +10,7 @@ access (see allowed_locations directive) to a list of mirrors that can be trusted. -There are further considerations with the experimental support for HTTPS CONNECT +There are further considerations with the support for HTTPS CONNECT proxying. Apt-cacher has no control over what is passed through the proxied connection as it is encrypted. Setting allowed_ssl_ports to anything other than the default (443 for HTTPS) and/or setting the allowed_ssl_locations to be more @@ -63,43 +63,8 @@ both Debian and Ubuntu boxes. There are frequent namespace clashes between the 2 distributions which have files with identical names, but different contents. -From version 1.7.0 there is experimental support for caching multiple -distributions using a single apt-cacher instance. See distinct_namespaces in man -apt-cacher(8) - -Prior to version 1.7.0 the only way to accommodate this was by running a -separate apt-cacher daemon for each Distribution on a different port with its -own cache directory. Even with version 1.7.0, this remains a safe and viable -option. - -To run multiple instances, run the first daemon from /etc/init.d/apt-cacher as -normal. For the second daemon, run it from /etc/rc.local with command line -options to override the configuration file. Alternatively, run the daemons from -/etc/inetd.conf: - -Example command-lines are: - - apt-cacher daemon_port=3142 cache_dir=/var/cache/apt-cacher-debian - allowed_locations=ftp.debian.org/debian - -and - - apt-cacher daemon_port=3141 cache_dir=/var/cache/apt-cacher-ubuntu - allowed_locations=archive.ubuntu.com/ubuntu - -It is important to set the allowed locations directive so that each daemon -only caches a particular distribution. This can be combined with the path_map -option: - - path_map=debian ftp.debian.org/debian - allowed_locations=debian - -and - - path_map=ubuntu archive.ubuntu.com/ubuntu - allowed_locations=ubuntu - -to provide a convenient interface for clients. +From version 1.7.0 there is support for caching multiple distributions using a +single apt-cacher instance. See distinct_namespaces in man apt-cacher(8) OLD DOCUMENTATION relevant for the CGI mode [deprecated]: @@ -149,4 +114,4 @@ introduced and curl was chosen as the default fetcher application. Also the usage of alternative HTTP daemons has been allowed. - -- Mark Hindley , Wed, 2 May 2012 08:24:15 z + -- Mark Hindley , Fri, 11 Oct 2013 19:09:42 z diff -Nru apt-cacher-1.7.6/debian/apt-cacher.8 apt-cacher-1.7.8/debian/apt-cacher.8 --- apt-cacher-1.7.6/debian/apt-cacher.8 2012-05-23 22:16:00.000000000 +0000 +++ apt-cacher-1.7.8/debian/apt-cacher.8 2013-10-21 15:41:44.000000000 +0000 @@ -174,12 +174,12 @@ just return errors if they are missing. .TP .B distinct_namespaces [0] -Set this to 1 to enable experimental support for caching multiple Distributions -(e.g Debian and Ubuntu) from a single apt\-cacher instance. When enabled, -package files are stored in a subdirectory, the name of which is derived from -the matching key of path_map or the part of the URL preceding 'pool' or -\'dists'. This is typically 'debian', 'ubuntu' or 'security'. This mechanism -prevents clashes between the Distributions. +Set this to 1 to enable support for caching multiple Distributions (e.g Debian +and Ubuntu) from a single apt\-cacher instance. When enabled, package files are +stored in a subdirectory, the name of which is derived from the matching key of +path_map or the part of the URL preceding 'pool' or 'dists'. This is typically +\'debian', 'ubuntu' or 'security'. This mechanism prevents clashes between the +Distributions. .IP If you enable this option, any existing namespace specific package files which are not in the correct subdirectory of cache_dir would be deleted by diff -Nru apt-cacher-1.7.6/debian/changelog apt-cacher-1.7.8/debian/changelog --- apt-cacher-1.7.6/debian/changelog 2012-10-03 07:24:54.000000000 +0000 +++ apt-cacher-1.7.8/debian/changelog 2013-10-21 15:42:46.000000000 +0000 @@ -1,3 +1,43 @@ +apt-cacher (1.7.8) unstable; urgency=low + + * Use sed to insert version number when building, therefore no need + to Build-Depend on perl any more. + * Only write body to cached file on success (200). + * Rework handling of If-Modified request response. Client errors also + count as EXPIRED. Delete cached files in these circumstances (closes: + #708884). + * return_file() never returns a retry code, so don't test for it. + * Update debian/control file description. Integrate experimental features + (multi-distro, Debian Bugs SOAP and HTTPS CONNECT) as established. + * Add Ubuntu 14.04 codename 'Trusty'. + + -- Mark Hindley Mon, 21 Oct 2013 16:42:46 +0100 + +apt-cacher (1.7.7) unstable; urgency=low + + * Add Ubuntu 13.10 codename 'Saucy'. + * Update to Standards version 3.9.4 (no changes). + * Use /proc/self/fd directly rather than rely on /dev/fd which can be + missing (closes: #699938). + * In precache script, make example to generate fake package list + architecture aware by using Dpkg::Arch. Add Suggests dependency on + libdpkg-perl (closes: #696523). + * Remove obsolete patch from patches/. + * Use new function cache_size() to obtain cache usage for configuration + item disk_usage_limit. Store cache size in shared mem and recaclulate + on a sliding scale from 0-20 seconds (closes: #689955). + * Don't use verbose _flock() in write_error_log() as it just makes + debug logs too full. + * Handle missing Last-Modified header: use the Date header to + generate the If-Modified request. + * Add Ubuntu 13.04 codename 'raring'. + * Add Italian debconf translation. File from Beatrice Torracca + (closes: #691351). + * Added Japenese debconf translation from victory + (closes: #691942). + + -- Mark Hindley Fri, 26 Apr 2013 11:55:15 +0100 + apt-cacher (1.7.6) unstable; urgency=low * Fix missing argument to $r->header when disk_usage_limit is configured diff -Nru apt-cacher-1.7.6/debian/control apt-cacher-1.7.8/debian/control --- apt-cacher-1.7.6/debian/control 2012-09-30 23:54:45.000000000 +0000 +++ apt-cacher-1.7.8/debian/control 2013-10-11 18:09:10.000000000 +0000 @@ -4,24 +4,24 @@ Maintainer: Mark Hindley Uploaders: Eduard Bloch Build-Depends: debhelper (>= 8.1.0~), po-debconf -Build-Depends-Indep: perl (>=5.6.0-16) -Standards-Version: 3.9.3 +Standards-Version: 3.9.4 Package: apt-cacher Architecture: all Pre-Depends: ${misc:Pre-Depends} -Depends: ${perl:Depends}, ${misc:Depends}, libwww-curl-perl (>=4.00), libwww-perl, libfreezethaw-perl, ed, libio-interface-perl, libfilesys-df-perl, libnetaddr-ip-perl, lsb-base (>= 3.2-14), update-inetd, libsys-syscall-perl, ucf (>= 0.28) +Depends: ${perl:Depends}, ${misc:Depends}, libwww-curl-perl (>=4.00), libwww-perl, libfreezethaw-perl, ed, libio-interface-perl, libfilesys-df-perl, libnetaddr-ip-perl, lsb-base (>= 3.2-14), update-inetd, libsys-syscall-perl, ucf (>= 0.28), libipc-shareable-perl Recommends: libberkeleydb-perl (>=0.34) -Suggests: libio-socket-inet6-perl +Suggests: libio-socket-inet6-perl, libdpkg-perl Description: Caching proxy for Debian package and source files - Apt-cacher performs caching of files requested by apt-get (or other clients - such as aptitude, synaptic). It is most useful for local area networks with - slow internet uplink or as a method for reducing multiple large downloads. + Apt-cacher performs caching of files requested by apt-get (or other APT clients + such as aptitude or synaptic). Apt-cacher can also proxy Debian Bugs SOAP + requests for apt-listbugs. It is most useful for local area networks with slow + internet uplink or as a method for reducing multiple large downloads. . - When a package is requested, the cache checks whether it already has the - requested version, in which case it sends the package to the user immediately. - If not, it downloads the package while streaming it to the user at the same - time. A local copy is then kept for use by other users. + When a file or package is requested, the cache checks whether it already has + the requested version, in which case it sends the package to the user + immediately. If not, it downloads the package while streaming it to the user + at the same time. A local copy is then kept for use by other users. . Apt-cacher has been optimized for best utilization of network bandwidth and efficiency even on slow low-memory servers. Multiple ways of installation are @@ -31,9 +31,8 @@ . The package includes utilities to clean the cache (removing obsolete package files), generate usage reports and import existing package files. Optional - features include a simple package checksum verification framework and IPv6 - support. Experimental features include support for FTP, HTTPS (proxying only), - Debian Bugs SOAP requests as well as the simultaneous caching of different + features include a file checksum verification framework, IPv6 support, FTP and + HTTPS (proxying only) support as well as the simultaneous caching of different repositories (e.g Debian and Ubuntu). . Apt-cacher can be used as a replacement for apt-proxy, with no need to modify diff -Nru apt-cacher-1.7.6/debian/po/it.po apt-cacher-1.7.8/debian/po/it.po --- apt-cacher-1.7.6/debian/po/it.po 1970-01-01 00:00:00.000000000 +0000 +++ apt-cacher-1.7.8/debian/po/it.po 2013-01-13 12:14:39.000000000 +0000 @@ -0,0 +1,60 @@ +# Italian description of apt-cacher debconf messages +# Copyright (C) 2012, Beatrice Torracca +# This file is distributed under the same license as the apt-cacher package. +# Beatrice Torracca , 2012. +msgid "" +msgstr "" +"Project-Id-Version: apt-cacher\n" +"Report-Msgid-Bugs-To: apt-cacher@packages.debian.org\n" +"POT-Creation-Date: 2011-06-25 21:31+0100\n" +"PO-Revision-Date: 2012-10-10 14:54+0200\n" +"Last-Translator: Beatrice Torracca \n" +"Language-Team: Italian \n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Virtaal 0.7.1\n" + +#. Type: select +#. Choices +#: ../apt-cacher.templates:1001 +msgid "daemon" +msgstr "demone" + +#. Type: select +#. Choices +#: ../apt-cacher.templates:1001 +msgid "inetd" +msgstr "inetd" + +#. Type: select +#. Choices +#: ../apt-cacher.templates:1001 +msgid "manual" +msgstr "manuale" + +#. Type: select +#. Description +#: ../apt-cacher.templates:1002 +msgid "Daemon mode for apt-cacher:" +msgstr "Modalità del demone di apt-cacher:" + +#. Type: select +#. Description +#: ../apt-cacher.templates:1002 +msgid "Please select the method for starting the apt-cacher daemon." +msgstr "Selezionare il metodo per avviare il demone di apt-cacher." + +#. Type: select +#. Description +#: ../apt-cacher.templates:1002 +msgid "" +"Choose \"daemon\" to run as a stand-alone daemon, \"inetd\" to run under " +"inetd or \"manual\" to use the (deprecated) CGI mode or some other manual " +"configuration." +msgstr "" +"Scegliere «demone» per eseguirlo come demone autonomo, «inetd» per eseguirlo " +"via inetd o «manuale» per usare la modalità CGI (deprecata) o qualche altra " +"configurazione manuale." diff -Nru apt-cacher-1.7.6/debian/po/ja.po apt-cacher-1.7.8/debian/po/ja.po --- apt-cacher-1.7.6/debian/po/ja.po 1970-01-01 00:00:00.000000000 +0000 +++ apt-cacher-1.7.8/debian/po/ja.po 2013-01-13 12:14:39.000000000 +0000 @@ -0,0 +1,58 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# victory , 2012. +# +msgid "" +msgstr "" +"Project-Id-Version: apt-cacher\n" +"Report-Msgid-Bugs-To: apt-cacher@packages.debian.org\n" +"POT-Creation-Date: 2012-10-04 14:25+0000\n" +"PO-Revision-Date: 2012-10-04 23:25+0900\n" +"Last-Translator: victory \n" +"Language-Team: Japanese \n" +"Language: ja\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#. Type: select +#. Choices +#: ../apt-cacher.templates:1001 +msgid "daemon" +msgstr "デーモン" + +#. Type: select +#. Choices +#: ../apt-cacher.templates:1001 +msgid "inetd" +msgstr "inetd" + +#. Type: select +#. Choices +#: ../apt-cacher.templates:1001 +msgid "manual" +msgstr "手動" + +#. Type: select +#. Description +#: ../apt-cacher.templates:1002 +msgid "Daemon mode for apt-cacher:" +msgstr "apt-cacher の起動モード:" + +#. Type: select +#. Description +#: ../apt-cacher.templates:1002 +msgid "Please select the method for starting the apt-cacher daemon." +msgstr "apt-cacher デーモンの起動方法を選択してください。" + +#. Type: select +#. Description +#: ../apt-cacher.templates:1002 +msgid "" +"Choose \"daemon\" to run as a stand-alone daemon, \"inetd\" to run under " +"inetd or \"manual\" to use the (deprecated) CGI mode or some other manual " +"configuration." +msgstr "" +"スタンドアロンで実行する場合は「デーモン」、inetd から起動させる場合は「inetd」" +"、(非推奨の) CGI モードその他の手動に設定する場合は「手動」を選択してください。" diff -Nru apt-cacher-1.7.6/debian/rules apt-cacher-1.7.8/debian/rules --- apt-cacher-1.7.6/debian/rules 2012-10-01 13:16:02.000000000 +0000 +++ apt-cacher-1.7.8/debian/rules 2013-10-11 18:09:10.000000000 +0000 @@ -61,7 +61,7 @@ install -m644 lib/Linux/IO_Prio.pm debian/apt-cacher/usr/share/apt-cacher/lib/Linux install -m755 libcurl.pl debian/apt-cacher/usr/share/apt-cacher/ install -m755 install.pl debian/apt-cacher/usr/share/apt-cacher/ - perl -pe 's/^my \$$version=.*/my \$$version="'$(shell dpkg-parsechangelog | grep ^Version | cut -f2 -d\ )'";/' -i $(CURDIR)/debian/apt-cacher/usr/share/apt-cacher/apt-cacher + sed -e "s/^my \$$version=.*/my \$$version='$(shell dpkg-parsechangelog | sed -n 's/^Version: //p')';/" -i $(CURDIR)/debian/apt-cacher/usr/share/apt-cacher/apt-cacher # Build architecture-independent files here. # Pass -i to all debhelper commands in this target to reduce clutter. diff -Nru apt-cacher-1.7.6/lib/apt-cacher.pl apt-cacher-1.7.8/lib/apt-cacher.pl --- apt-cacher-1.7.6/lib/apt-cacher.pl 2012-10-03 07:21:42.000000000 +0000 +++ apt-cacher-1.7.8/lib/apt-cacher.pl 2013-10-21 15:41:44.000000000 +0000 @@ -55,7 +55,25 @@ request_timeout => 30, return_buffer_size => 1048576, # 1Mb reverse_path_map => 1, - ubuntu_release_names => join(', ', qw(dapper edgy feisty gutsy hardy intrepid jaunty karmic lucid maverick natty oneiric precise quantal)), + ubuntu_release_names => join(', ', qw( + dapper + edgy + feisty + gutsy + hardy + intrepid + jaunty + karmic + lucid + maverick + natty + oneiric + precise + quantal + raring + saucy + trusty + )), use_proxy => 0, use_proxy_auth => 0, user => $>, @@ -358,7 +376,7 @@ my ($fh) = @_; die 'Not a GLOB' unless ref $fh eq 'GLOB'; - return '/dev/fd/' . $fh->fileno; + return '/proc/self/fd/' . $fh->fileno; } # Delete cached files by filehandle diff -Nru apt-cacher-1.7.6/patches/experimental-patch-with-thread-change-to-allow-better-concaching.diff apt-cacher-1.7.8/patches/experimental-patch-with-thread-change-to-allow-better-concaching.diff --- apt-cacher-1.7.6/patches/experimental-patch-with-thread-change-to-allow-better-concaching.diff 2008-11-16 20:45:09.000000000 +0000 +++ apt-cacher-1.7.8/patches/experimental-patch-with-thread-change-to-allow-better-concaching.diff 1970-01-01 00:00:00.000000000 +0000 @@ -1,95 +0,0 @@ -Index: apt-cacher2 -=================================================================== ---- apt-cacher2 (Revision 2104) -+++ apt-cacher2 (Arbeitskopie) -@@ -757,6 +757,9 @@ - - my $fromfile; # handle for the reader - -+ my $pid=0; -+ my $doing_download=0; -+ - # download or not decission. Also releases the global lock - dl_check: - if( !$force_download && -e $cached_head && -e $cached_file) { -@@ -782,7 +785,8 @@ - &release_global_lock; - } - else { -- # (re) download them -+ # (re) download them, needs to fork the data returning thread while the main thread is doing the download -+ $doing_download=1; - unlink($cached_file, $cached_head, $complete_file, $notify_file); - debug_message("file does not exist or so, creating it"); - # Set the status to MISS so the log file can show it had to be downloaded -@@ -792,47 +796,53 @@ - } - - # the writer releases the global lock after opening the target file -- my $pid = fork(); -+ $pid = fork(); - if ($pid < 0) { - barf("fork() failed"); - } -- if ($pid == 0) { -- # child, the fetcher thread -- undef %childPids; -+ if ($pid != 0) { -+ # parent thread, do the download -+ $childPids{$pid}=1; - sysopen($pkfd, $cached_file, O_RDWR|O_CREAT|O_EXCL, 0644) || barf("Unable to store files"); - open ( $chfd, ">$cached_head"); - - if (flock($pkfd, LOCK_EX)) { - -- # release the global lock within fetcher thread after the -+ # release the global lock within fetching thread after the - # file has been created - &release_global_lock; - - &fetch_store ($host, $uri); - -- exit 0; -+ #exit 0; - } - else { - barf("Problem locking the target file!"); - } -- # child exiting above, so or so - } -- # parent continues -- $childPids{$pid}=1; -+ undef %childPids; - debug_message("registred child process: $pid"); - } - -+ # return data either in the forked child or in the main thread if not doing download -+ if( !$doing_download || $pid==0) { -+ # the child, does only return data and exit - -- &return_file (\$fromfile, $send_head_only); -- debug_message("Package sent"); -+ &return_file (\$fromfile, $send_head_only); -+ debug_message("Package sent"); - -- # Write all the stuff to the log file -- writeaccesslog("$cache_status", "$new_filename"); -- if(!check_sum($new_filename)) { -- writeerrorlog("ALARM! Faulty package in local cache detected! Replacing $new_filename in the next run"); -- unlink $cached_file; -- exit(4); -+ # Write all the stuff to the log file -+ writeaccesslog("$cache_status", "$new_filename"); -+ if(!check_sum($new_filename)) { -+ writeerrorlog("ALARM! Faulty package in local cache detected! Replacing $new_filename in the next run"); -+ unlink $cached_file; -+ exit(4); -+ } - } -+ # if this is a child process, just terminate, otherwise wait for child to finish the data printout -+ exit(0) if($doing_download && $pid==0); -+ wait if($pid != 0); # FIXME, saugt -+ - } - - }