[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-2-0' - wsd/ClientSession.cpp wsd/TileCache.cpp wsd/TileCache.hpp

Jan Holesovsky kendy at collabora.com
Tue Jan 17 15:54:59 UTC 2017


 wsd/ClientSession.cpp |    8 ++++----
 wsd/TileCache.cpp     |   13 +++++++------
 wsd/TileCache.hpp     |    5 ++++-
 3 files changed, 15 insertions(+), 11 deletions(-)

New commits:
commit 35fc8d1dd00eea066811a2035c1deebbf1064273
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Tue Jan 17 16:42:31 2017 +0100

    Fix error handling in reading of the cached values.
    
    Change-Id: I9f56f09786feb11326707d19cc0367a027ebefff

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 5adcf3a..e7a81ab 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -305,8 +305,8 @@ bool ClientSession::getCommandValues(const char *buffer, int length, StringToken
         return sendTextFrame("error: cmd=commandvalues kind=syntax");
     }
 
-    const std::string cmdValues = docBroker->tileCache().getTextFile("cmdValues" + command + ".txt");
-    if (cmdValues.size() > 0)
+    std::string cmdValues;
+    if (docBroker->tileCache().getTextFile("cmdValues" + command + ".txt", cmdValues))
     {
         return sendTextFrame(cmdValues);
     }
@@ -317,8 +317,8 @@ bool ClientSession::getCommandValues(const char *buffer, int length, StringToken
 bool ClientSession::getPartPageRectangles(const char *buffer, int length,
                                           const std::shared_ptr<DocumentBroker>& docBroker)
 {
-    const std::string partPageRectangles = docBroker->tileCache().getTextFile("partpagerectangles.txt");
-    if (partPageRectangles.size() > 0)
+    std::string partPageRectangles;
+    if (docBroker->tileCache().getTextFile("partpagerectangles.txt", partPageRectangles))
     {
         return sendTextFrame(partPageRectangles);
     }
diff --git a/wsd/TileCache.cpp b/wsd/TileCache.cpp
index 9bac2a6..13463de 100644
--- a/wsd/TileCache.cpp
+++ b/wsd/TileCache.cpp
@@ -57,9 +57,10 @@ TileCache::TileCache(const std::string& docURL,
                 << "] modifiedTime=" << (modifiedTime.raw()/1000000)
                 << " getLastModified()=" << (getLastModified().raw()/1000000) << Log::end;
     File directory(_cacheDir);
+    std::string unsaved;
     if (directory.exists() &&
         (getLastModified() < modifiedTime ||
-         getTextFile("unsaved.txt") != ""))
+         getTextFile("unsaved.txt", unsaved)))
     {
         // Document changed externally or modifications were not saved after all. Cache not useful.
         FileUtil::removeFile(_cacheDir, true);
@@ -229,7 +230,7 @@ void TileCache::saveTileAndNotify(const TileDesc& tile, const char *data, const
     }
 }
 
-std::string TileCache::getTextFile(const std::string& fileName)
+bool TileCache::getTextFile(const std::string& fileName, std::string& content)
 {
     const std::string fullFileName =  _cacheDir + "/" + fileName;
 
@@ -237,7 +238,7 @@ std::string TileCache::getTextFile(const std::string& fileName)
     if (!textStream.is_open())
     {
         Log::info("Could not open " + fullFileName);
-        return "";
+        return false;
     }
 
     std::vector<char> buffer;
@@ -251,10 +252,10 @@ std::string TileCache::getTextFile(const std::string& fileName)
     if (buffer.size() > 0 && buffer.back() == '\n')
         buffer.pop_back();
 
-    std::string result = std::string(buffer.data(), buffer.size());
-    Log::info("Read '" + LOOLProtocol::getAbbreviatedMessage(result.c_str(), result.size()) + "' from " + fullFileName);
+    content = std::string(buffer.data(), buffer.size());
+    Log::info("Read '" + LOOLProtocol::getAbbreviatedMessage(content.c_str(), content.size()) + "' from " + fullFileName);
 
-    return result;
+    return true;
 }
 
 void TileCache::saveTextFile(const std::string& text, const std::string& fileName)
diff --git a/wsd/TileCache.hpp b/wsd/TileCache.hpp
index b9b2f60..3573fde 100644
--- a/wsd/TileCache.hpp
+++ b/wsd/TileCache.hpp
@@ -49,7 +49,10 @@ public:
 
     void saveTileAndNotify(const TileDesc& tile, const char* data, const size_t size);
 
-    std::string getTextFile(const std::string& fileName);
+    /// Get the content of a cache file.
+    /// @param content Valid only when the call returns true.
+    /// @return true when the file actually exists
+    bool getTextFile(const std::string& fileName, std::string& content);
 
     // Save some text into a file in the cache directory
     void saveTextFile(const std::string& text, const std::string& fileName);


More information about the Libreoffice-commits mailing list