]>
git.ipfire.org Git - thirdparty/squid.git/blob - scripts/flag_truncs.pl
3 ## Copyright (C) 1996-2016 The Squid Software Foundation and contributors
5 ## Squid software is distributed under GPLv2+ license and includes
6 ## contributions from numerous individuals and organizations.
7 ## Please see the COPYING and CONTRIBUTORS files for details.
10 # flag_truncs.pl - martin hamilton <m.t.hamilton@lut.ac.uk>
12 # Check the CERN/Harvest/Netscape cache for truncated objects
13 # - i.e. those for which there is a "Content-length:" HTTP header,
14 # and this does not match the size of the cached object
19 # -c -> just count the number of objects with a Content-length header
20 # -d -> turn on debugging output
22 # pass filenames on command line or via STDIN
23 @things = $#ARGV >= 0 ?
@ARGV : <STDIN
>;
25 $total_objects = 0, $content_length = 0;
27 # iterate through them
28 foreach $thing (@things) {
31 $opt_d && (print STDERR
">> inspecting: $thing\n");
32 next if -d
"$thing"; # don't want directories
34 $size = (stat($thing))[$ST_SIZE]||next;
35 $opt_d && (print STDERR
">> stat: $size\n");
36 print "$thing\n", next if ($size == 0);
40 $count = 0, $expected = 0;
41 open(IN
, "$thing") || die "Can't open cached object $thing: $!";
45 print STDERR
">> inspecting $_\n" if $opt_d;
46 last if /^(\s+|)$/; # drop out after the end of the HTTP headers
48 # skip if cached file appeared since script started running
50 print STDERR
">> skipping $_\n" if $opt_d;
54 if (/^Content-length:\s+(\d+)/i) {
62 next if $expected == 0; # no Content-length header
64 # looked at the headers now
65 $difference = $size - $count;
66 $opt_d && print STDERR
">> real: ", $difference, ", expected: $expected\n";
67 if ($difference != $expected) {
68 print "$thing (expected: $expected, got: $difference)\n";
72 print "$content_length out of $total_objects had Content-length: header\n"