]> git.lyx.org Git - lyx.git/blobdiff - src/support/FileName.cpp
Make GraphicsConverter threadsafe
[lyx.git] / src / support / FileName.cpp
index 08d726e0c6347de476fa0950798ffa5527574b69..05492f66d14c85a9230ca64ac79937aacd107132 100644 (file)
@@ -17,6 +17,7 @@
 #include "support/filetools.h"
 #include "support/lassert.h"
 #include "support/lstrings.h"
+#include "support/mutex.h"
 #include "support/qstring_helpers.h"
 #include "support/os.h"
 #include "support/Package.h"
@@ -220,7 +221,6 @@ void FileName::erase()
 bool FileName::copyTo(FileName const & name, bool keepsymlink) const
 {
        FileNameSet visited;
-       visited.insert(*this);
        return copyTo(name, keepsymlink, visited);
 }
 
@@ -230,6 +230,7 @@ bool FileName::copyTo(FileName const & name, bool keepsymlink,
 {
        LYXERR(Debug::FILES, "Copying " << name << " keep symlink: " << keepsymlink);
        if (keepsymlink && name.isSymLink()) {
+               visited.insert(*this);
                FileName const target(fromqstr(name.d->fi.symLinkTarget()));
                if (visited.find(target) != visited.end()) {
                        LYXERR(Debug::FILES, "Found circular symlink: " << target);
@@ -454,40 +455,6 @@ FileNameList FileName::dirList(string const & ext) const
 }
 
 
-static string createTempFile(QString const & mask)
-{
-       // FIXME: This is not safe. QTemporaryFile creates a file in open(),
-       //        but the file is deleted when qt_tmp goes out of scope.
-       //        Therefore the next call to createTempFile() may create the
-       //        same file again. To make this safe the QTemporaryFile object
-       //        needs to be kept for the whole life time of the temp file name.
-       //        This can be achieved by using the TempFile class.
-       QTemporaryFile qt_tmp(mask + ".XXXXXXXXXXXX");
-       if (qt_tmp.open()) {
-               string const temp_file = fromqstr(qt_tmp.fileName());
-               LYXERR(Debug::FILES, "Temporary file `" << temp_file << "' created.");
-               return temp_file;
-       }
-       LYXERR(Debug::FILES, "Unable to create temporary file with following template: "
-               << qt_tmp.fileTemplate());
-       return string();
-}
-
-
-FileName FileName::tempName(FileName const & temp_dir, string const & mask)
-{
-       QFileInfo tmp_fi(QDir(temp_dir.d->fi.absoluteFilePath()), toqstr(mask));
-       LYXERR(Debug::FILES, "Temporary file in " << tmp_fi.absoluteFilePath());
-       return FileName(createTempFile(tmp_fi.absoluteFilePath()));
-}
-
-
-FileName FileName::tempName(string const & mask)
-{
-       return tempName(package().temp_dir(), mask);
-}
-
-
 FileName FileName::getcwd()
 {
        // return makeAbsPath("."); would create an infinite loop
@@ -944,13 +911,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;
@@ -976,7 +945,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;