]> git.lyx.org Git - lyx.git/blobdiff - src/support/FileName.cpp
add debug function which prints the callstack to stderr, disabled by default
[lyx.git] / src / support / FileName.cpp
index e8a8ab997be6c6a1c6ca728f61c56427c0d0e0ad..a16278fce4d21f720be487e6dad7913b728cb146 100644 (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,7 +559,11 @@ unsigned long FileName::checksum() const
                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);
@@ -564,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
 
@@ -922,12 +931,6 @@ string FileName::guessFormatFromContents() const
 
                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
@@ -952,57 +955,6 @@ bool FileName::isZippedFile() const
 }
 
 
-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
@@ -1166,7 +1118,7 @@ string DocFileName::mangledFileName(string const & dir) const
        // 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++] = '_';