From 7f1fa090e3a2fcde49c8bf06440520ff57fd8331 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Mon, 7 Jul 2014 21:58:24 +0200 Subject: [PATCH] Make preview filename generation threadsafe Threadsafety is ensured by the atomic file name generation in TempFile. --- src/graphics/PreviewLoader.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/graphics/PreviewLoader.cpp b/src/graphics/PreviewLoader.cpp index b4d78e0ab5..b5d464d344 100644 --- a/src/graphics/PreviewLoader.cpp +++ b/src/graphics/PreviewLoader.cpp @@ -38,6 +38,7 @@ #include "support/lstrings.h" #include "support/bind.h" +#include "support/TempFile.h" #include #include @@ -59,11 +60,11 @@ typedef list PendingSnippets; typedef vector BitmapFile; -string const unique_filename(string const & bufferpath) +FileName const unique_tex_filename(FileName const & bufferpath) { - static int theCounter = 0; - string const filename = lyx::convert(theCounter++) + "lyxpreview"; - return addName(bufferpath, filename); + TempFile tempfile(bufferpath, "lyxpreviewXXXXXX.tex"); + tempfile.setAutoRemove(false); + return tempfile.name(); } @@ -529,9 +530,10 @@ void PreviewLoader::Impl::startLoading(bool wait) LYXERR(Debug::GRAPHICS, "PreviewLoader::startLoading()"); // As used by the LaTeX file and by the resulting image files - string const directory = buffer_.temppath(); + FileName const directory(buffer_.temppath()); - string const filename_base = unique_filename(directory); + FileName const latexfile = unique_tex_filename(directory); + string const filename_base = removeExtension(latexfile.absFileName()); // Create an InProgress instance to place in the map of all // such processes if it starts correctly. @@ -541,8 +543,6 @@ void PreviewLoader::Impl::startLoading(bool wait) pending_.clear(); // Output the LaTeX file. - FileName const latexfile(filename_base + ".tex"); - // we use the encoding of the buffer Encoding const & enc = buffer_.params().encoding(); ofdocstream of; -- 2.39.5