mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-25 09:35:39 +00:00
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:
parent
5510a81769
commit
c664b63949
@ -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 FileName::checksum() const
|
||||||
{
|
{
|
||||||
unsigned long result = 0;
|
unsigned long result = 0;
|
||||||
@ -543,9 +559,11 @@ unsigned long FileName::checksum() const
|
|||||||
return result;
|
return result;
|
||||||
|
|
||||||
struct stat info;
|
struct stat info;
|
||||||
if (fstat(fd, &info))
|
if (fstat(fd, &info)){
|
||||||
// fstat fails on samba shares (bug 5891)
|
// 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,
|
void * mm = mmap(0, info.st_size, PROT_READ,
|
||||||
MAP_PRIVATE, fd, 0);
|
MAP_PRIVATE, fd, 0);
|
||||||
@ -566,18 +584,7 @@ unsigned long FileName::checksum() const
|
|||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
#else // no SUM_WITH_MMAP
|
#else // no SUM_WITH_MMAP
|
||||||
|
result = checksum_ifstream_fallback(file);
|
||||||
//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();
|
|
||||||
|
|
||||||
#endif // SUM_WITH_MMAP
|
#endif // SUM_WITH_MMAP
|
||||||
#endif // QT_VERSION
|
#endif // QT_VERSION
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user