]> git.ipfire.org Git - thirdparty/squid.git/blame - scripts/flag_truncs.pl
Initial revision
[thirdparty/squid.git] / scripts / flag_truncs.pl
CommitLineData
090089c4 1#!/usr/local/bin/perl
2
3# flag_truncs.pl - martin hamilton <m.t.hamilton@lut.ac.uk>
4#
5# Check the CERN/Harvest/Netscape cache for truncated objects
6# - i.e. those for which there is a "Content-length:" HTTP header,
7# and this does not match the size of the cached object
8
9# $Id: flag_truncs.pl,v 1.1 1996/02/22 06:23:57 wessels Exp $
10
11require "getopts.pl";
12require "stat.pl";
13&Getopts("cd");
14# -c -> just count the number of objects with a Content-length header
15# -d -> turn on debugging output
16
17# pass filenames on command line or via STDIN
18@things = $#ARGV >= 0 ? @ARGV : <STDIN>;
19
20$total_objects = 0, $content_length = 0;
21
22# iterate through them
23foreach $thing (@things) {
24 chop $thing;
25
26 $opt_d && (print STDERR ">> inspecting: $thing\n");
27 next if -d "$thing"; # don't want directories
28
29 $size = (stat($thing))[$ST_SIZE]||next;
30 $opt_d && (print STDERR ">> stat: $size\n");
31 print "$thing\n", next if ($size == 0);
32
33 $total_objects++;
34
35 $count = 0, $expected = 0;
36 open(IN, "$thing") || die "Can't open cached object $thing: $!";
37 while(<IN>) {
38 $count += length($_);
39 chop;
40 print STDERR ">> inspecting $_\n" if $opt_d;
41 last if /^(\s+|)$/; # drop out after the end of the HTTP headers
42
43 # skip if cached file appeared since script started running
44 if (-M $_ < 0) {
45 print STDERR ">> skipping $_\n" if $opt_d;
46 next;
47 }
48
49 if (/^Content-length:\s+(\d+)/i) {
50 $expected = $1;
51 $content_length++;
52 }
53 }
54 close(IN);
55
56 next if $opt_c;
57 next if $expected == 0; # no Content-length header
58
59 # looked at the headers now
60 $difference = $size - $count;
61 $opt_d && print STDERR ">> real: ", $difference, ", expected: $expected\n";
62 if ($difference != $expected) {
63 print "$thing (expected: $expected, got: $difference)\n";
64 }
65}
66
67print "$content_length out of $total_objects had Content-length: header\n"
68 if $opt_c;