}
+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;
return result;
struct stat info;
- fstat(fd, &info);
+ if (fstat(fd, &info)){
+ // fstat fails on samba shares (bug 5891)
+ close(fd);
+ return checksum_ifstream_fallback(file);
+ }
void * mm = mmap(0, info.st_size, PROT_READ,
MAP_PRIVATE, fd, 0);
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
else if (contains(str, "BITPIX"))
format = "fits";
-
- else if (contains(str, encryptionGuessString())) {
- string ver = token(str, '-', 1);
- string key = token(str, '-', 2);
- format = encryptionGuessString() + "-" + ver + "-" + key;
- }
}
- // Dia knows also compressed form
- if ((format == "gzip") && (!compare_ascii_no_case(extension(), "dia")))
- format="dia";
-
if (!format.empty()) {
LYXERR(Debug::GRAPHICS, "Recognised Fileformat: " << format);
return format;
}
-bool FileName::isEncryptedFile() const
-{
- string const type = guessFormatFromContents();
- string const guess = encryptionGuessString();
- return toqstr(type).contains(toqstr(guess));
-}
-
-std::string FileName::encryptionGuessString()
-{
- return "LyXEncrypted";
-}
-
-std::string FileName::encryptionPrefix(int version, int keytype)
-{
- // A encrypted file starts with the bytes "LyXEncrypted-001-001-"
- // the first number describes the encryption version which could
- // change with the time. the second number describes how the key
- // is generated, ATM only passwords are supported.
- QString guess = toqstr(encryptionGuessString());
- QString vstr = QString::number(version);
- QString kstr = QString::number(keytype);
- vstr = vstr.rightJustified(3, '0');
- kstr = kstr.rightJustified(3, '0');
- return fromqstr(guess + "-" + vstr + "-" + kstr + "-");
-}
-
-
-int FileName::encryptionVersion() const
-{
- string const type = guessFormatFromContents();
- string ver = token(type, '-', 1);
- bool ok = false;
- int version = toqstr(ver).toInt(&ok);
- if (!ok)
- return -1;
- return version;
-}
-
-int FileName::encryptionKeytype() const
-{
- string const type = guessFormatFromContents();
- string ver = token(type, '-', 2);
- bool ok = false;
- int keytype = toqstr(ver).toInt(&ok);
- if (!ok)
- return -1;
- return keytype;
-}
-
-
-
docstring const FileName::relPath(string const & path) const
{
// FIXME UNICODE
// in the name.
static string const keep = "abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "+,-0123456789;=";
+ "+-0123456789;=";
string::size_type pos = 0;
while ((pos = mname.find_first_not_of(keep, pos)) != string::npos)
mname[pos++] = '_';