[Libreoffice-commits] online.git: loolwsd/Util.cpp loolwsd/Util.hpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Fri May 13 12:57:11 UTC 2016


 loolwsd/Util.cpp |   10 ++++++++++
 loolwsd/Util.hpp |   12 +-----------
 2 files changed, 11 insertions(+), 11 deletions(-)

New commits:
commit 68b8b2af4f154f99612762c1ff2d7b2197a23162
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Fri May 13 08:44:22 2016 -0400

    loolwsd: improve temp file creation and delayed delete
    
    Change-Id: I174b87f1aceaacee58121bc60edb420004e69c44
    Reviewed-on: https://gerrit.libreoffice.org/24967
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/Util.cpp b/loolwsd/Util.cpp
index 519cb66..a814ae2 100644
--- a/loolwsd/Util.cpp
+++ b/loolwsd/Util.cpp
@@ -36,6 +36,7 @@
 #include <Poco/Process.h>
 #include <Poco/Thread.h>
 #include <Poco/Timestamp.h>
+#include <Poco/TemporaryFile.h>
 #include <Poco/Util/Application.h>
 
 #include "Common.hpp"
@@ -127,6 +128,15 @@ namespace Util
         }
     }
 
+    std::string getTempFilePath(const std::string srcDir, const std::string& srcFilename)
+    {
+        const std::string srcPath = srcDir + '/' + srcFilename;
+        const std::string dstPath = Poco::Path::temp() + encodeId(rng::getNext()) + '_' + srcFilename;
+        Poco::File(srcPath).copyTo(dstPath);
+        Poco::TemporaryFile::registerForDeletion(dstPath);
+        return dstPath;
+    }
+
     bool windowingAvailable()
     {
         return std::getenv("DISPLAY") != nullptr;
diff --git a/loolwsd/Util.hpp b/loolwsd/Util.hpp
index 28cdb94..5340899 100644
--- a/loolwsd/Util.hpp
+++ b/loolwsd/Util.hpp
@@ -90,17 +90,7 @@ namespace Util
     /// Primarily used by tests to avoid tainting the originals.
     /// srcDir shouldn't end with '/' and srcFilename shouldn't contain '/'.
     /// Returns the created file path.
-    inline
-    std::string getTempFilePath(const std::string srcDir, const std::string& srcFilename)
-    {
-        const std::string srcPath = srcDir + '/' + srcFilename;
-
-        std::string dstPath = std::tmpnam(nullptr);
-        dstPath += '_' + srcFilename;
-
-        Poco::File(srcPath).copyTo(dstPath);
-        return dstPath;
-    }
+    std::string getTempFilePath(const std::string srcDir, const std::string& srcFilename);
 
     /// Returns the name of the signal.
     const char *signalName(int signo);


More information about the Libreoffice-commits mailing list