Detect if file is actually a directory in support/lyxsum.cpp, fix bug 3622

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18449 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Bo Peng 2007-05-22 00:27:56 +00:00
parent 0c64c056a5
commit 2d90c65500

View File

@ -17,12 +17,14 @@
#include "support/FileName.h" #include "support/FileName.h"
#include <boost/crc.hpp> #include <boost/crc.hpp>
#include <boost/filesystem/operations.hpp>
#include <algorithm> #include <algorithm>
using std::endl; using std::endl;
using std::string; using std::string;
namespace fs = boost::filesystem;
// OK, this is ugly, but it is the only workaround I found to compile // 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. // with gcc (any version) on a system which uses a non-GNU toolchain.
@ -126,8 +128,13 @@ unsigned long sum(FileName const & file)
LYXERR(Debug::FILES) << "lyx::sum() using istreambuf_iterator (fast)" LYXERR(Debug::FILES) << "lyx::sum() using istreambuf_iterator (fast)"
<< endl; << endl;
ifstream ifs(file.toFilesystemEncoding().c_str()); string filename = file.toFilesystemEncoding();
if (!ifs) return 0; // 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); istreambuf_iterator<char> beg(ifs);
istreambuf_iterator<char> end; istreambuf_iterator<char> end;
@ -145,8 +152,13 @@ unsigned long sum(FileName const & file)
<< "lyx::sum() using istream_iterator (slow as a snail)" << "lyx::sum() using istream_iterator (slow as a snail)"
<< endl; << endl;
ifstream ifs(file.toFilesystemEncoding().c_str()); string filename = file.toFilesystemEncoding();
if (!ifs) return 0; // 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); ifs.unsetf(ios::skipws);
istream_iterator<char> beg(ifs); istream_iterator<char> beg(ifs);