]> git.lyx.org Git - features.git/commitdiff
Delete temp file after usage
authorGeorg Baum <baum@lyx.org>
Mon, 1 Apr 2013 10:24:24 +0000 (12:24 +0200)
committerGeorg Baum <baum@lyx.org>
Mon, 1 Apr 2013 10:24:24 +0000 (12:24 +0200)
src/Buffer.cpp
src/support/FileName.cpp

index 9103abda0baf043599f1cd8e9d8b7df146f3d082..5a834cfe2fe134ca3019422535434a8923ee942e 100644 (file)
@@ -988,22 +988,24 @@ bool Buffer::readString(string const & s)
        FileName const fn = FileName::tempName("Buffer_readString");
 
        int file_format;
-       ReadStatus const ret_plf = parseLyXFormat(lex, fn, file_format);
-       if (ret_plf != ReadSuccess)
-               return ret_plf;
+       bool success = parseLyXFormat(lex, fn, file_format) == ReadSuccess;
 
-       if (file_format != LYX_FORMAT) {
+       if (success && file_format != LYX_FORMAT) {
                // We need to call lyx2lyx, so write the input to a file
                ofstream os(fn.toFilesystemEncoding().c_str());
                os << s;
                os.close();
                // lyxvc in readFile
-               return readFile(fn) == ReadSuccess;
+               if (readFile(fn) != ReadSuccess)
+                       success = false;
        }
 
-       if (readDocument(lex))
-               return false;
-       return true;
+       if (success)
+               if (readDocument(lex))
+                       success = false;
+       if (fn.exists())
+               fn.removeFile();
+       return success;
 }
 
 
index 96317bed2798cf798906eecf010e29291438e835..3cc18bc9ae0b286716e32dd3e1bf30220462cf19 100644 (file)
@@ -437,6 +437,11 @@ 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.
        QTemporaryFile qt_tmp(mask);
        if (qt_tmp.open()) {
                string const temp_file = fromqstr(qt_tmp.fileName());