Boost logo

Boost :

From: Michael Klein (michael.klein_at_[hidden])
Date: 2007-03-29 08:03:15


Hello list,

the directory_iterator (current CVS) doesn't work if the iterated
directory resides on an NFS mount and fails with an exception in
boost::filesystem::basic_directory_iterator's constructor.

The NFS server here runs Linux, and the iterator fails at least on
clients running Solaris (Invalid argument) or HP-UX (Operation not
supported).

This reason is because of the call to pathconf(_PC_NAME_MAX) in
directory_iterator::dir_itr_first() which fails for directories
residing on NFS mounts, probably because the client doesn't know about
the server's limits.

Although arbitrary assumptions are usally not the best idea I think it's
reasonable to use PATH_MAX as maximum length in this case. Not being
able to use a directory_iterator on a NFS mount is a rather severe
limitation, IMHO.

As a workaround I'm using this patch right now:

--- boost.orig/boost/libs/filesystem/src/operations.cpp
+++ boots/boost/libs/filesystem/src/operations.cpp
@@ -1187,7 +1187,21 @@
            return error_code( errno, errno_ecat );
          target = dummy_first_name;
          long pc_name_max( ::pathconf( dir.c_str(), _PC_NAME_MAX ) );
- if ( pc_name_max == -1L ) return error_code( errno, errno_ecat );
+ if ( pc_name_max == -1L )
+ {
+ switch ( errno )
+ {
+ case EINVAL:
+#ifdef EOPNOTSUPP
+ case EOPNOTSUPP: // HP-UX returns this
+#endif
+ pc_name_max = PATH_MAX;
+ break;
+
+ default:
+ return error_code( errno, errno_ecat );
+ }
+ }
          dirent de;
          buffer = std::malloc( (sizeof(dirent) - sizeof(de.d_name))
            + static_cast<std::size_t>( pc_name_max ) + 1 );

Any opinions?

Kind regards,

-- 
Michael
#exclude <windows.h>

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk