This is not good:
$ file -kb /usr/home/dan/ports/www/p5-HTTP-Size/Makefile
Apple Old Partition data block size: 20069, first type: ${PORTSDIR}/www/p5-HTML-SimpleL, name: I \, number of blocks: 1953460746,
It should read:
$ file -kb /usr/home/dan/ports/sysutils/bacula-server/Makefile
ASCII English text
Why do I care? The file in question has been fetched from the FreeBSD repository (via cvsweb). I need to ensure it’s not an HTML error file. Or more correctly, that it is an ASCII file, not an HTML file. I want to know that I’ve fetched a proper result.
I used to do this:
sub LooksLikeAMakefile($) { my $Makefile = shift; my $Result = 1; my $filetype = `file -b $Makefile`; chomp($filetype); print "$filetype\n"; if (index($filetype, 'HTML', 0) != -1) { print "nope, that's HTML, not a Makefile as far as I'm concerned....\n"; $Result = 0; } return $Result; }
That usually worked. It makes sure that HTML appears somewhere in the output of the file command. The first example above fails in this code. Here is the patch I’m going to use instead:
sub LooksLikeAMakefile($) { my $Makefile = shift; my $Result = 1; my $Command = "file -b $Makefile"; my $filetype = `$Command`; chomp($filetype); print "\n$Command gives:\n"; print "$filetype\n\n"; # look for HTML at the start of the file output my $index = index($filetype, 'HTML', 0); print "index result " . $index . "\n"; if ($index == 0) { print "nope, that's HTML, not a Makefile as far as I'm concerned....\n"; $Result = 0; } return $Result; }
This code is on my development server now.
What is the difference? I’m now checking that the HTML appears at the start of the file output, not just somewhere within the output. And I’m printing a bit more debugging output.