I traced this bug a little bit and find some weird things going on.
I am surprised that ifstream(".") returns OK, as shown in my test program. #include <fstream> #include <iostream> int main() { std::ifstream ifs("."); if (!ifs) std::cout << "error \n"; else std::cout << "OK \n"; return 1; } Therefore, lyxsum.cpp, line 134 will not fail if a directory is passed, and then do_crc will fail. I propose the attached patch. Can I apply? Cheers, Bo
Index: src/support/lyxsum.cpp =================================================================== --- src/support/lyxsum.cpp (revision 18422) +++ src/support/lyxsum.cpp (working copy) @@ -17,12 +17,14 @@ #include "support/FileName.h" #include <boost/crc.hpp> +#include <boost/filesystem/operations.hpp> #include <algorithm> using std::endl; using std::string; +namespace fs = boost::filesystem; // OK, this is ugly, but it is the only workaround I found to compile // with gcc (any version) on a system which uses a non-GNU toolchain. @@ -126,7 +128,10 @@ LYXERR(Debug::FILES) << "lyx::sum() using istreambuf_iterator (fast)" << endl; - ifstream ifs(file.toFilesystemEncoding().c_str()); + string filename = file.toFilesystemEncoding(); + // a directory may be passed here so we need to test it. (bug 3622) + if (fs::is_directory(filename)) return 0; + ifstream ifs(filename.c_str()); if (!ifs) return 0; istreambuf_iterator<char> beg(ifs); @@ -145,7 +150,10 @@ << "lyx::sum() using istream_iterator (slow as a snail)" << endl; - ifstream ifs(file.toFilesystemEncoding().c_str()); + string filename = file.toFilesystemEncoding(); + // a directory may be passed here so we need to test it. (bug 3622) + if (fs::is_directory(filename)) return 0; + ifstream ifs(filename.c_str()); if (!ifs) return 0; ifs.unsetf(ios::skipws);