* Add run-time check that IO::Dirent is functioning correctly,
[BackupPC.git] / lib / BackupPC / Lib.pm
index 88db7f8..011e394 100644 (file)
@@ -11,7 +11,7 @@
 #   Craig Barratt  <cbarratt@users.sourceforge.net>
 #
 # COPYRIGHT
 #   Craig Barratt  <cbarratt@users.sourceforge.net>
 #
 # COPYRIGHT
-#   Copyright (C) 2001-2003  Craig Barratt
+#   Copyright (C) 2001-2007  Craig Barratt
 #
 #   This program is free software; you can redistribute it and/or modify
 #   it under the terms of the GNU General Public License as published by
 #
 #   This program is free software; you can redistribute it and/or modify
 #   it under the terms of the GNU General Public License as published by
@@ -72,7 +72,20 @@ require DynaLoader;
 
 BEGIN {
     eval "use IO::Dirent qw( readdirent DT_DIR );";
 
 BEGIN {
     eval "use IO::Dirent qw( readdirent DT_DIR );";
-    $IODirentOk = 1 if ( !$@ );
+    if ( !$@ && opendir(my $fh, ".") ) {
+        #
+        # Make sure the IO::Dirent really works - some installs
+        # on certain file systems don't return a valid type.
+        #
+        my $dt_dir = eval("DT_DIR");
+        foreach my $e ( readdirent($fh) ) {
+            if ( $e->{name} eq "." && $e->{type} == $dt_dir ) {
+                $IODirentOk = 1;
+                last;
+            }
+        }
+        closedir($fh);
+    }
 };
 
 #
 };
 
 #