]> git.lyx.org Git - lyx.git/blobdiff - src/support/FileName.cpp
Fix bugs #6078 and #9364
[lyx.git] / src / support / FileName.cpp
index 95880a0e79f7cf91e49239f68a9f5aa5ff71fd0d..9506666d27fc0de2dfbfe26b440db50904d9354d 100644 (file)
@@ -17,7 +17,7 @@
 #include "support/filetools.h"
 #include "support/lassert.h"
 #include "support/lstrings.h"
-#include "support/qstring_helpers.h"
+#include "support/mutex.h"
 #include "support/os.h"
 #include "support/Package.h"
 #include "support/qstring_helpers.h"
@@ -248,7 +248,7 @@ bool FileName::copyTo(FileName const & name, bool keepsymlink,
 
 bool FileName::renameTo(FileName const & name) const
 {
-       LYXERR(Debug::FILES, "Renaming " << name);
+       LYXERR(Debug::FILES, "Renaming " << name << " as " << *this);
        bool success = QFile::rename(d->fi.absoluteFilePath(), name.d->fi.absoluteFilePath());
        if (!success)
                LYXERR0("Could not rename file " << *this << " to " << name);
@@ -258,7 +258,7 @@ bool FileName::renameTo(FileName const & name) const
 
 bool FileName::moveTo(FileName const & name) const
 {
-       LYXERR(Debug::FILES, "Moving " << name);
+       LYXERR(Debug::FILES, "Moving " << name << " to " << *this);
        QFile::remove(name.d->fi.absoluteFilePath());
 
        bool success = QFile::rename(d->fi.absoluteFilePath(),
@@ -490,6 +490,12 @@ bool FileName::chdir() const
 }
 
 
+bool FileName::link(FileName const & name) const
+{
+       return QFile::link(toqstr(absFileName()), toqstr(name.absFileName()));
+}
+
+
 unsigned long checksum_ifstream_fallback(char const * file)
 {
        unsigned long result = 0;
@@ -910,13 +916,15 @@ string DocFileName::outputFileName(string const & path) const
 
 string DocFileName::mangledFileName(string const & dir) const
 {
-       // FIXME THREAD
        // Concurrent access to these variables is possible.
 
        // We need to make sure that every DocFileName instance for a given
        // filename returns the same mangled name.
        typedef map<string, string> MangledMap;
        static MangledMap mangledNames;
+       static Mutex mangledMutex;
+       // this locks both access to mangledNames and counter below 
+       Mutex::Locker lock(&mangledMutex);
        MangledMap::const_iterator const it = mangledNames.find(absFileName());
        if (it != mangledNames.end())
                return (*it).second;
@@ -942,7 +950,6 @@ string DocFileName::mangledFileName(string const & dir) const
        // Add the extension back on
        mname = support::changeExtension(mname, getExtension(name));
 
-       // FIXME THREAD
        // Prepend a counter to the filename. This is necessary to make
        // the mangled name unique.
        static int counter = 0;