Index: /main/trunk/greenstone2/perllib/FileUtils.pm
===================================================================
--- /main/trunk/greenstone2/perllib/FileUtils.pm	(revision 27375)
+++ /main/trunk/greenstone2/perllib/FileUtils.pm	(revision 27376)
@@ -71,74 +71,14 @@
 ################################################################################
 
-## @function differentFiles()
-#
-# this function returns -1 if either file is not found assumes that
-# $file1 and $file2 are absolute file names or in the current
-# directory $file2 is allowed to be newer than $file1
-#
-sub differentFiles
-{
-  my ($file1, $file2, $verbosity) = @_;
-  $verbosity = 1 unless defined $verbosity;
-
-  $file1 =~ s/\/+$//;
-  $file2 =~ s/\/+$//;
-
-  my ($file1name) = $file1 =~ /\/([^\/]*)$/;
-  my ($file2name) = $file2 =~ /\/([^\/]*)$/;
-
-  return -1 unless (-e $file1 && -e $file2);
-  if ($file1name ne $file2name)
-  {
-    print STDERR "filenames are not the same\n" if ($verbosity >= 2);
-    return 1;
-  }
-
-  my @file1stat = stat ($file1);
-  my @file2stat = stat ($file2);
-
-  if (-d $file1)
-  {
-    if (! -d $file2)
-    {
-      print STDERR "one file is a directory\n" if ($verbosity >= 2);
-      return 1;
-    }
-    return 0;
-  }
-
-  # both must be regular files
-  unless (-f $file1 && -f $file2)
-  {
-    print STDERR "one file is not a regular file\n" if ($verbosity >= 2);
-    return 1;
-  }
-
-  # the size of the files must be the same
-  if ($file1stat[7] != $file2stat[7])
-  {
-    print STDERR "different sized files\n" if ($verbosity >= 2);
-    return 1;
-  }
-
-  # the second file cannot be older than the first
-  if ($file1stat[9] > $file2stat[9])
-  {
-    print STDERR "file is older\n" if ($verbosity >= 2);
-    return 1;
-  }
-
-  return 0;
-}
-## differentFiles()
-
-## @function directoryExists()
-#
-sub directoryExists
+
+## @function canRead()
+#
+sub canRead
 {
   my ($filename_full_path) = @_;
-  return &fileTest($filename_full_path, '-d');
-}
-## directoryExists()
+  return &fileTest($filename_full_path, '-R');
+}
+## canRead()
+
 
 ## @function closeFileHandle
@@ -150,4 +90,5 @@
 }
 ## closeFileHandle()
+
 
 ## @function copyFiles()
@@ -200,4 +141,5 @@
 }
 ## copyFiles()
+
 
 ## @function copyFilesRecursive()
@@ -275,4 +217,5 @@
 }
 ## copyFilesRecursive()
+
 
 ## @function copyFilesRecursiveNoSVN()
@@ -354,4 +297,5 @@
 ## copyFilesRecursiveNoSVN()
 
+
 ## @function copyFilesRecursiveTopLevel()
 #
@@ -432,4 +376,78 @@
 ## copyFilesRecursiveTopLevel()
 
+
+## @function differentFiles()
+#
+# this function returns -1 if either file is not found assumes that
+# $file1 and $file2 are absolute file names or in the current
+# directory $file2 is allowed to be newer than $file1
+#
+sub differentFiles
+{
+  my ($file1, $file2, $verbosity) = @_;
+  $verbosity = 1 unless defined $verbosity;
+
+  $file1 =~ s/\/+$//;
+  $file2 =~ s/\/+$//;
+
+  my ($file1name) = $file1 =~ /\/([^\/]*)$/;
+  my ($file2name) = $file2 =~ /\/([^\/]*)$/;
+
+  return -1 unless (-e $file1 && -e $file2);
+  if ($file1name ne $file2name)
+  {
+    print STDERR "filenames are not the same\n" if ($verbosity >= 2);
+    return 1;
+  }
+
+  my @file1stat = stat ($file1);
+  my @file2stat = stat ($file2);
+
+  if (-d $file1)
+  {
+    if (! -d $file2)
+    {
+      print STDERR "one file is a directory\n" if ($verbosity >= 2);
+      return 1;
+    }
+    return 0;
+  }
+
+  # both must be regular files
+  unless (-f $file1 && -f $file2)
+  {
+    print STDERR "one file is not a regular file\n" if ($verbosity >= 2);
+    return 1;
+  }
+
+  # the size of the files must be the same
+  if ($file1stat[7] != $file2stat[7])
+  {
+    print STDERR "different sized files\n" if ($verbosity >= 2);
+    return 1;
+  }
+
+  # the second file cannot be older than the first
+  if ($file1stat[9] > $file2stat[9])
+  {
+    print STDERR "file is older\n" if ($verbosity >= 2);
+    return 1;
+  }
+
+  return 0;
+}
+## differentFiles()
+
+
+## @function directoryExists()
+#
+sub directoryExists
+{
+  my ($filename_full_path) = @_;
+  return &fileTest($filename_full_path, '-d');
+}
+## directoryExists()
+
+
 ## @function fileExists()
 #
@@ -677,4 +695,5 @@
     }
   }
+ return 1;
 }
 ## makeAllDirectories()
@@ -857,8 +876,19 @@
   my $fh_ref = shift(@_);
   my $encoding = shift(@_);
-  my $mode_symbol = '<';
-  if ($mode eq 'w')
+  my $mode_symbol;
+  if ($mode eq 'w' || $mode eq '>')
   {
     $mode_symbol = '>';
+    $mode = 'writing';
+  }
+  elsif ($mode eq 'a' || $mode eq '>>')
+  {
+    $mode_symbol = '>>';
+    $mode = 'appending';
+  }
+  else
+  {
+    $mode_symbol = '<';
+    $mode = 'reading';
   }
   if (defined $encoding)
@@ -868,9 +898,4 @@
   if (!open($$fh_ref, $mode_symbol, $path))
   {
-    $mode = 'writing';
-    if ($mode eq '>')
-    {
-      $mode = 'reading';
-    }
     die("Error! Failed to open file for " . $mode . ": " . $path . "\n");
   }
