[ic] Bug (and fix) for File::CounterFile and MS Windows

Bill Randle billr@exgate.tek.com
Thu, 15 Mar 2001 14:37:36 -0800


As part of getting a site running under Windows I ran into a problem where
the File::CounterFile messed up when it was given a DOS style directory path.
For example, lets say you set SratchDir to "C:\Minivend\tmp"; what will
happen is that File::CounterFile will try to create the file (e.g.)
"/usr/tmp/C:\Minivend\tmp/addr_ctr/1/2/127_0_0_1" - which needless to say
does not work too well.

The problem is that File::CounterFile does not recognize the "C:/" as
specifying an absolute pathname. The fix shown below replaces the existing
file name test with the test used in Vend::Util.

This problem is in the version of CounterFile.pm shipped with Minivend 4.04
and Interchange 4.6.3.

	-Bill

--- CounterFile.pm.orig Sat May  6 08:27:40 2000
+++ CounterFile.pm      Tue Mar 13 15:54:15 2001
@@ -101,13 +101,21 @@
             fallback => 1,
 );
 
+# File test taken from Vend::Util and tweaked to check for relative paths, too
+
+my $abs_rel_pat = $^O =~ /win32/i ? '^([a-z]:)?[\\\\/\.]' : '^[/\.]';
+
+sub fname_is_absolute_or_relative {
+    my($file) = @_;
+    $file =~ m{$abs_rel_pat}oi ;
+}
 
 sub new
 {
     my($class, $file, $initial) = @_;
     croak "No file specified\n" unless defined $file;
 
-    $file = "$DEFAULT_DIR/$file" unless $file =~ /^[\.\/]/;
+    $file = "$DEFAULT_DIR/$file" unless fname_is_absolute_or_relative($file);
     $initial = $DEFAULT_INITIAL unless defined $initial;
 
     my $value;