Better handling checksum on samba - allow fallback to ifstream.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@38022 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Pavel Sanda 2011-03-24 10:12:55 +00:00
parent 5510a81769
commit c664b63949

View File

@ -492,6 +492,22 @@ bool FileName::chdir() const
}
unsigned long checksum_ifstream_fallback(char const * file)
{
unsigned long result = 0;
//LYXERR(Debug::FILES, "lyx::sum() using istreambuf_iterator (fast)");
ifstream ifs(file, ios_base::in | ios_base::binary);
if (!ifs)
return result;
istreambuf_iterator<char> beg(ifs);
istreambuf_iterator<char> end;
boost::crc_32_type crc;
crc = for_each(beg, end, crc);
result = crc.checksum();
return result;
}
unsigned long FileName::checksum() const
{
unsigned long result = 0;
@ -543,9 +559,11 @@ unsigned long FileName::checksum() const
return result;
struct stat info;
if (fstat(fd, &info))
if (fstat(fd, &info)){
// fstat fails on samba shares (bug 5891)
return result;
close(fd);
return checksum_ifstream_fallback(file);
}
void * mm = mmap(0, info.st_size, PROT_READ,
MAP_PRIVATE, fd, 0);
@ -566,18 +584,7 @@ unsigned long FileName::checksum() const
close(fd);
#else // no SUM_WITH_MMAP
//LYXERR(Debug::FILES, "lyx::sum() using istreambuf_iterator (fast)");
ifstream ifs(file, ios_base::in | ios_base::binary);
if (!ifs)
return result;
istreambuf_iterator<char> beg(ifs);
istreambuf_iterator<char> end;
boost::crc_32_type crc;
crc = for_each(beg, end, crc);
result = crc.checksum();
result = checksum_ifstream_fallback(file);
#endif // SUM_WITH_MMAP
#endif // QT_VERSION