I am looking at errors like: http://article.gmane.org/gmane.editors.lyx.general/41854/match=boost+filesystem+exists which boil down to LyX dying from a boost exception when some files/directories are not readable. Indeed, boost::fs:exists can throw an exception: BOOST_FS_FUNC(bool) exists( const Path & ph ) { system_error_type ec; file_status result( detail::status_api( ph.external_file_string(), ec ) ); if ( ec ) boost::throw_exception( basic_filesystem_error<Path>( "boost::filesystem::exists", ph, ec ) ); return exists( result ); }
I wrote the patch below and was happy (although I cannot test this particular bug...), but then grep tells me pegase: grep -r fs::exists src|wc -l 70 What are we going to do with these 70 calls? Handle them one by one? What about disabling boost exceptions instead? Can we do it? Also I see in src/boost.cpp: #ifndef BOOST_NO_EXCEPTIONS void throw_exception(std::exception const & e) { lyxerr << "Exception caught:\n" << e.what() << endl; BOOST_ASSERT(false); } #endif How come this code is not used? The output does not match what the original reported wrote. JMarc
svndiff src/support/filetools.cpp Index: src/support/filetools.cpp =================================================================== --- src/support/filetools.cpp (révision 21001) +++ src/support/filetools.cpp (copie de travail) @@ -159,8 +159,17 @@ string const quoteName(string const & na bool isFileReadable(FileName const & filename) { - std::string const path = filename.toFilesystemEncoding(); - return fs::exists(path) && !fs::is_directory(path) && fs::is_readable(path); + try { + // it seems that fs::exists can throw an exception + // when the file is not readable. + std::string const path = filename.toFilesystemEncoding(); + return fs::exists(path) + && !fs::is_directory(path) + && fs::is_readable(path); + } catch (fs::filesystem_error const & fe){ + return false; + } + }