[Libreoffice-commits] online.git: 6 commits - loolwsd/DocumentBroker.cpp loolwsd/DocumentBroker.hpp loolwsd/Log.cpp loolwsd/LOOLWSD.cpp loolwsd/loolwsd.xml.in loolwsd/Makefile.am loolwsd/MasterProcessSession.cpp loolwsd/MasterProcessSession.hpp loolwsd/protocol.txt loolwsd/test loolwsd/TileCache.cpp loolwsd/TileCache.hpp
Tor Lillqvist
tml at collabora.com
Fri Apr 22 14:51:55 UTC 2016
loolwsd/DocumentBroker.cpp | 10 +
loolwsd/DocumentBroker.hpp | 2
loolwsd/LOOLWSD.cpp | 2
loolwsd/Log.cpp | 2
loolwsd/Makefile.am | 2
loolwsd/MasterProcessSession.cpp | 36 ------
loolwsd/MasterProcessSession.hpp | 2
loolwsd/TileCache.cpp | 212 +++++++++------------------------------
loolwsd/TileCache.hpp | 45 ++------
loolwsd/loolwsd.xml.in | 2
loolwsd/protocol.txt | 5
loolwsd/test/httpwstest.cpp | 60 +++++------
12 files changed, 108 insertions(+), 272 deletions(-)
New commits:
commit f46855eb2570527f342950f9f07b7560a55fc91c
Author: Tor Lillqvist <tml at collabora.com>
Date: Fri Apr 22 16:36:09 2016 +0300
It is not a cause for warning if we are removing a file
Use info() instead. Also, only log the info if the file actually
existed and was removed. We don't want misleading noise logging about
removing files that were not there. Use std::remove() directly to
avoid unnecessary layers that just make it harder to know whether the
removal worked or not.
diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp
index a730b4d..6fbdc63 100644
--- a/loolwsd/TileCache.cpp
+++ b/loolwsd/TileCache.cpp
@@ -291,8 +291,10 @@ void TileCache::invalidateTiles(const std::string& tiles)
void TileCache::removeFile(const std::string& fileName)
{
- Log::warn("Removing file: " + _cacheDir + "/" + fileName);
- Util::removeFile(_cacheDir + "/" + fileName);
+ const std::string fullFileName = _cacheDir + "/" + fileName;
+
+ if (std::remove(fullFileName.c_str()) == 0)
+ Log::info("Removed file: " + _cacheDir + "/" + fileName);
}
std::string TileCache::cacheFileName(int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, int tileHeight)
commit c80b7388ed6aec4b75bf236bab1701c5e9007427
Author: Tor Lillqvist <tml at collabora.com>
Date: Fri Apr 22 16:07:04 2016 +0300
The JS client never sends any 'invalidatetiles'
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index 9da0dac..cae00ce 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -320,7 +320,6 @@ bool MasterProcessSession::_handleInput(const char *buffer, int length)
tokens[0] != "gettextselection" &&
tokens[0] != "paste" &&
tokens[0] != "insertfile" &&
- tokens[0] != "invalidatetiles" &&
tokens[0] != "key" &&
tokens[0] != "mouse" &&
tokens[0] != "partpagerectangles" &&
@@ -360,10 +359,6 @@ bool MasterProcessSession::_handleInput(const char *buffer, int length)
{
return getPartPageRectangles(buffer, length);
}
- else if (tokens[0] == "invalidatetiles")
- {
- return invalidateTiles(buffer, length, tokens);
- }
else if (tokens[0] == "renderfont")
{
sendFontRendering(buffer, length, tokens);
@@ -412,25 +407,6 @@ bool MasterProcessSession::_handleInput(const char *buffer, int length)
return true;
}
-bool MasterProcessSession::invalidateTiles(const char* /*buffer*/, int /*length*/, StringTokenizer& tokens)
-{
- int part, tilePosX, tilePosY, tileWidth, tileHeight;
-
- if (tokens.count() != 6 ||
- !getTokenInteger(tokens[1], "part", part) ||
- !getTokenInteger(tokens[2], "tileposx", tilePosX) ||
- !getTokenInteger(tokens[3], "tileposy", tilePosY) ||
- !getTokenInteger(tokens[4], "tilewidth", tileWidth) ||
- !getTokenInteger(tokens[5], "tileheight", tileHeight))
- {
- sendTextFrame("error: cmd=invalidatetiles kind=syntax");
- return false;
- }
-
- _docBroker->tileCache().invalidateTiles(_curPart, tilePosX, tilePosY, tileWidth, tileHeight);
- return true;
-}
-
bool MasterProcessSession::loadDocument(const char* /*buffer*/, int /*length*/, StringTokenizer& tokens)
{
if (tokens.count() < 2)
diff --git a/loolwsd/MasterProcessSession.hpp b/loolwsd/MasterProcessSession.hpp
index beffa34..16d9b64 100644
--- a/loolwsd/MasterProcessSession.hpp
+++ b/loolwsd/MasterProcessSession.hpp
@@ -58,8 +58,6 @@ public:
bool _bLoadError = false;
protected:
- bool invalidateTiles(const char *buffer, int length, Poco::StringTokenizer& tokens);
-
virtual bool loadDocument(const char *buffer, int length, Poco::StringTokenizer& tokens) override;
virtual void sendTile(const char *buffer, int length, Poco::StringTokenizer& tokens) override;
diff --git a/loolwsd/protocol.txt b/loolwsd/protocol.txt
index ce45761..22e8682 100644
--- a/loolwsd/protocol.txt
+++ b/loolwsd/protocol.txt
@@ -40,11 +40,6 @@ insertfile name=<name> type=<type>
Inserts the file with the name <name> into the document, we currently support type = 'graphic'
-invalidatetiles part=<partNumber> tileposx=<xpos> tileposy=<ypos> tilewidth=<tileWidth> tileheight=<tileHeight>
-
- All parameters are numbers. Makes the server remove any cached
- tiles intersecting with the given area (in twips).
-
key type=<type> char=<charcode> key=<keycode>
<type> is 'input' or 'up', <charcode> and <keycode> are numbers.
commit 7d2a1d9048dfa979dd617d51919d2b60bec9e0b0
Author: Tor Lillqvist <tml at collabora.com>
Date: Fri Apr 22 14:11:57 2016 +0300
I always keep doing 'make cache-clean'
diff --git a/loolwsd/Makefile.am b/loolwsd/Makefile.am
index c7ac590..8c34c85 100644
--- a/loolwsd/Makefile.am
+++ b/loolwsd/Makefile.am
@@ -144,7 +144,7 @@ SYSTEM_STAMP =
endif
-clean-cache:
+clean-cache cache-clean:
# Intentionally don't use "*" below... Avoid risk of accidentally running rm -rf /*
test -n "@LOOLWSD_CACHEDIR@" && rm -rf "@LOOLWSD_CACHEDIR@"/[0-9a-f]
commit bff5748cd9bc296a2c72017f23d0d53f97b98381
Author: Tor Lillqvist <tml at collabora.com>
Date: Fri Apr 22 14:00:11 2016 +0300
No need to have separate "editing" and "persistent" tile caches
All changes are supposed to be persistent. This simplifies the tile
caching code quite a lot.
The TileCache object no longer needs to keep any state whether the
document is being edited or whether it has been modified without
saving etc.
Update the modtime.txt file after saving the document. Otherwise the
tile cache would wrongly be considered invalid next time.
As a sanity check, we put a flag file 'unsaved.txt' into the cache
directory whenever we get a callback that indicates the document has
been modified, and remove it when the document is saved. If the flag
file is present when we take an existing tile cache into use, we can't
trust it.
Even after these changes, we still don't use an existing tile cache as
much (or at all?) as we could, though. The INVALIDATE_TILES EMPTY
callback that LO does early on in a conection causes us to remove all
cached tiles...
diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 5a21bad..deab8fc 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -156,9 +156,11 @@ bool DocumentBroker::save()
{
_isModified = false;
_lastSaveTime = std::chrono::steady_clock::now();
- _tileCache->documentSaved();
+ _tileCache->setUnsavedChanges(false);
Log::debug("Saved to URI [" + uri + "] and updated tile cache.");
_saveCV.notify_all();
+ const auto fileInfo = _storage->getFileInfo(_uriPublic);
+ _tileCache->saveLastModified(fileInfo._modifiedTime);
return true;
}
@@ -329,4 +331,10 @@ bool DocumentBroker::canDestroy()
return _markToDestroy;
}
+void DocumentBroker::setModified(const bool value)
+{
+ _tileCache->setUnsavedChanges(value);
+ _isModified = value;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index b696a65..3c39b24 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -178,7 +178,7 @@ public:
bool canDestroy();
bool isMarkedToDestroy() const { return _markToDestroy; }
bool isModified() const { return _isModified; }
- void setModified(const bool value) { _isModified = value; }
+ void setModified(const bool value);
private:
const Poco::URI _uriPublic;
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 6a377fc..56dcdb6 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -1254,7 +1254,7 @@ void LOOLWSD::defineOptions(OptionSet& optionSet)
.repeatable(false)
.argument("port number"));
- optionSet.addOption(Option("cache", "", "Path to a directory where to keep the persistent tile cache (default: " + std::string(LOOLWSD_CACHEDIR) + ").")
+ optionSet.addOption(Option("cache", "", "Path to a directory where to keep the tile cache (default: " + std::string(LOOLWSD_CACHEDIR) + ").")
.required(false)
.repeatable(false)
.argument("directory"));
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index dd1bdc4..9da0dac 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -268,16 +268,8 @@ bool MasterProcessSession::_handleInput(const char *buffer, int length)
if (tokens.count() > 1 && !tokens[1].empty())
_docBroker->tileCache().saveTextFile(std::string(buffer, length), "partpagerectangles.txt");
}
- else if (tokens[0] == "invalidatecursor:")
- {
- _docBroker->tileCache().setEditing(true);
- }
else if (tokens[0] == "invalidatetiles:")
{
- // FIXME temporarily, set the editing on the 1st invalidate, TODO extend
- // the protocol so that the client can set the editing or view only.
- _docBroker->tileCache().setEditing(true);
-
assert(firstLine.size() == static_cast<std::string::size_type>(length));
_docBroker->tileCache().invalidateTiles(firstLine);
}
@@ -435,10 +427,6 @@ bool MasterProcessSession::invalidateTiles(const char* /*buffer*/, int /*length*
return false;
}
- // FIXME temporarily, set the editing on the 1st invalidate, TODO extend
- // the protocol so that the client can set the editing or view only.
- _docBroker->tileCache().setEditing(true);
-
_docBroker->tileCache().invalidateTiles(_curPart, tilePosX, tilePosY, tileWidth, tileHeight);
return true;
}
diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp
index 4847135..a730b4d 100644
--- a/loolwsd/TileCache.cpp
+++ b/loolwsd/TileCache.cpp
@@ -65,32 +65,22 @@ std::vector<std::weak_ptr<MasterProcessSession>> TileBeingRendered::getSubscribe
TileCache::TileCache(const std::string& docURL,
const Timestamp& modifiedTime,
- const std::string& rootCacheDir) :
+ const std::string& cacheDir) :
_docURL(docURL),
- _rootCacheDir(rootCacheDir),
- _persCacheDir(Path(rootCacheDir, "persistent").toString()),
- _editCacheDir(Path(rootCacheDir, "editing").toString()),
- _isEditing(false),
- _hasUnsavedChanges(false)
+ _cacheDir(cacheDir)
{
- Log::info("TileCache ctor for uri [" + _docURL + "].");
- const bool cleanEverything = (getLastModified() < modifiedTime);
- if (cleanEverything)
+ Log::info("TileCache ctor for uri [" + _docURL + "] modifiedTime=" + std::to_string(modifiedTime.raw()/1000000) + " getLastModified()=" + std::to_string(getLastModified().raw()/1000000));
+ File directory(_cacheDir);
+ if (directory.exists() &&
+ (getLastModified() < modifiedTime ||
+ getTextFile("unsaved.txt") != ""))
{
- // document changed externally, clean up everything
- Util::removeFile(_rootCacheDir, true);
- Log::info("Completely cleared tilecache: " + _rootCacheDir);
- }
- else
- {
- // remove only the Editing cache
- Util::removeFile(_editCacheDir, true);
- Log::info("Cleared the editing tilecache: " + _editCacheDir);
+ // Document changed externally or modifications were not saved after all. Cache not useful.
+ Util::removeFile(_cacheDir, true);
+ Log::info("Completely cleared tile cache: " + _cacheDir);
}
- File(_rootCacheDir).createDirectories();
- File(_editCacheDir).createDirectories();
- File(_persCacheDir).createDirectories();
+ File(_cacheDir).createDirectories();
saveLastModified(modifiedTime);
}
@@ -141,35 +131,12 @@ void TileCache::forgetTileBeingRendered(int part, int width, int height, int til
std::unique_ptr<std::fstream> TileCache::lookupTile(int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, int tileHeight)
{
- const std::string cachedName = cacheFileName(part, width, height, tilePosX, tilePosY, tileWidth, tileHeight);
-
- if (_hasUnsavedChanges)
- {
- // Try the Editing cache first.
- Path path(_editCacheDir, cachedName);
- const std::string fileName = path.toString();
- std::unique_ptr<std::fstream> result(new std::fstream(fileName, std::ios::in));
- if (result && result->is_open())
- {
- Log::trace("Found editing tile: " + fileName);
- return result;
- }
- }
-
- // Skip tiles scheduled for removal from the Persistent cache (on save)
- if (_toBeRemoved.find(cachedName) != _toBeRemoved.end())
- {
- Log::trace("Skipping perishable tile: " + cachedName);
- return nullptr;
- }
+ const std::string fileName = _cacheDir + "/" + cacheFileName(part, width, height, tilePosX, tilePosY, tileWidth, tileHeight);
- // Default to the content of the Persistent cache.
- Path path(_persCacheDir, cachedName);
- const std::string fileName = path.toString();
std::unique_ptr<std::fstream> result(new std::fstream(fileName, std::ios::in));
if (result && result->is_open())
{
- Log::trace("Found persistent tile: " + fileName);
+ Log::trace("Found cache tile: " + fileName);
return result;
}
@@ -178,128 +145,74 @@ std::unique_ptr<std::fstream> TileCache::lookupTile(int part, int width, int hei
void TileCache::saveTile(int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, int tileHeight, const char *data, size_t size)
{
- if (_isEditing)
- {
- _hasUnsavedChanges = true;
- }
+ const std::string fileName = _cacheDir + "/" + cacheFileName(part, width, height, tilePosX, tilePosY, tileWidth, tileHeight);
- const std::string dirName = cacheDirName(_hasUnsavedChanges);
-
- const std::string fileName = dirName + "/" + cacheFileName(part, width, height, tilePosX, tilePosY, tileWidth, tileHeight);
- Log::trace() << "Saving "
- << (_hasUnsavedChanges ? "editing" : "persistent") <<
- " tile: " << fileName << Log::end;
+ Log::trace() << "Saving cache tile: " << fileName << Log::end;
std::fstream outStream(fileName, std::ios::out);
outStream.write(data, size);
outStream.close();
}
-std::string TileCache::getTextFile(std::string fileName)
+std::string TileCache::getTextFile(const std::string& fileName)
{
- const auto textFile = std::string("/" + fileName);
-
- std::string dirName = _persCacheDir;
- if (_hasUnsavedChanges)
- {
- // try the Editing cache first, and prefer it if it exists
- const std::string editingDirName = _editCacheDir;
- File dir(editingDirName);
-
- File text(editingDirName + textFile);
- if (dir.exists() && dir.isDirectory() && text.exists() && !text.isDirectory())
- dirName = editingDirName;
- }
-
- if (!File(dirName).exists() || !File(dirName).isDirectory())
- {
- return "";
- }
+ const std::string fullFileName = _cacheDir + "/" + fileName;
- fileName = dirName + textFile;
- std::fstream textStream(fileName, std::ios::in);
+ std::fstream textStream(fullFileName, std::ios::in);
if (!textStream.is_open())
{
+ Log::info("Could not open " + fullFileName);
return "";
}
- std::vector<char> result;
+ std::vector<char> buffer;
textStream.seekg(0, std::ios_base::end);
std::streamsize size = textStream.tellg();
- result.resize(size);
+ buffer.resize(size);
textStream.seekg(0, std::ios_base::beg);
- textStream.read(result.data(), size);
+ textStream.read(buffer.data(), size);
textStream.close();
- if (result[result.size()-1] == '\n')
- result.resize(result.size() - 1);
+ if (buffer.size() > 0 && buffer.back() == '\n')
+ buffer.pop_back();
+
+ std::string result = std::string(buffer.data(), buffer.size());
+ Log::info("Read '" + result + "' from " + fullFileName);
- return std::string(result.data(), result.size());
+ return result;
}
-void TileCache::documentSaved()
+void TileCache::saveTextFile(const std::string& text, const std::string& fileName)
{
- Log::debug("Persisting editing tiles.");
-
- // first remove the invalidated tiles from the Persistent cache
- for (const auto& it : _toBeRemoved)
- {
- Log::debug("Removing tile: " + _persCacheDir + "/" + it);
- Util::removeFile(_persCacheDir + "/" + it);
- }
+ const std::string fullFileName = _cacheDir + "/" + fileName;
+ std::fstream textStream(fullFileName, std::ios::out);
- _toBeRemoved.clear();
-
- // then move the new tiles from the Editing cache to Persistent
- try
+ if (!textStream.is_open())
{
- std::unique_lock<std::mutex> lock(_cacheMutex);
- for (auto tileIterator = DirectoryIterator(_editCacheDir); tileIterator != DirectoryIterator(); ++tileIterator)
- {
- Log::debug("Moving tile: " + tileIterator.path().toString() + " to " + _persCacheDir);
- tileIterator->moveTo(_persCacheDir);
- }
-
- // update status
- _hasUnsavedChanges = false;
-
- // FIXME should we take the exact time of the file for the local files?
- saveLastModified(Timestamp());
+ Log::error("Could not save '" + text + "' to " + fullFileName);
+ return;
}
- catch (const FileException& exc)
+ else
{
- // Just log this exception, ignore it otherwise
- Log::error() << "TileCache::documentSaved: Exception: " << exc.displayText()
- << (exc.nested() ? " (" + exc.nested()->displayText() + ")" : "")
- << Log::end;
+ Log::info("Saving '" + text + "' to " + fullFileName);
}
-}
-void TileCache::setEditing(bool editing)
-{
- _isEditing = editing;
+ textStream << text << std::endl;
+ textStream.close();
}
-void TileCache::saveTextFile(const std::string& text, std::string fileName)
+void TileCache::setUnsavedChanges(bool state)
{
- const std::string dirName = cacheDirName(_isEditing);
-
- StringTokenizer tokens(text, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
-
- fileName = dirName + "/" + fileName;
- std::fstream textStream(fileName, std::ios::out);
-
- if (!textStream.is_open())
- return;
-
- textStream << text << std::endl;
- textStream.close();
+ if (state)
+ saveTextFile("1", "unsaved.txt");
+ else
+ removeFile("unsaved.txt");
}
void TileCache::saveRendering(const std::string& name, const std::string& dir, const char *data, size_t size)
{
// can fonts be invalidated?
- const std::string dirName = _persCacheDir + "/" + dir;
+ const std::string dirName = _cacheDir + "/" + dir;
File(dirName).createDirectories();
@@ -312,7 +225,7 @@ void TileCache::saveRendering(const std::string& name, const std::string& dir, c
std::unique_ptr<std::fstream> TileCache::lookupRendering(const std::string& name, const std::string& dir)
{
- const std::string dirName = _persCacheDir + "/" + dir;
+ const std::string dirName = _cacheDir + "/" + dir;
const std::string fileName = dirName + "/" + name;
File directory(dirName);
@@ -332,12 +245,11 @@ void TileCache::invalidateTiles(int part, int x, int y, int width, int height)
<< ", width: " << width
<< ", height: " << height << Log::end;
- // in the Editing cache, remove immediately
- File editingDir(_editCacheDir);
- if (editingDir.exists() && editingDir.isDirectory())
+ File dir(_cacheDir);
+ if (dir.exists() && dir.isDirectory())
{
std::unique_lock<std::mutex> lock(_cacheMutex);
- for (auto tileIterator = DirectoryIterator(editingDir); tileIterator != DirectoryIterator(); ++tileIterator)
+ for (auto tileIterator = DirectoryIterator(dir); tileIterator != DirectoryIterator(); ++tileIterator)
{
const std::string fileName = tileIterator.path().getFileName();
if (intersectsTile(fileName, part, x, y, width, height))
@@ -347,20 +259,6 @@ void TileCache::invalidateTiles(int part, int x, int y, int width, int height)
}
}
}
-
- // in the Persistent cache, add to _toBeRemoved for removal on save
- File persistentDir(_persCacheDir);
- if (persistentDir.exists() && persistentDir.isDirectory())
- {
- for (auto tileIterator = DirectoryIterator(persistentDir); tileIterator != DirectoryIterator(); ++tileIterator)
- {
- const std::string fileName = tileIterator.path().getFileName();
- if (_toBeRemoved.find(fileName) == _toBeRemoved.end() && intersectsTile(fileName, part, x, y, width, height))
- {
- _toBeRemoved.insert(fileName);
- }
- }
- }
}
void TileCache::invalidateTiles(const std::string& tiles)
@@ -393,14 +291,8 @@ void TileCache::invalidateTiles(const std::string& tiles)
void TileCache::removeFile(const std::string& fileName)
{
- Log::warn("Removing tile: " + fileName);
- Util::removeFile(_persCacheDir + "/" + fileName);
- Util::removeFile(_editCacheDir + "/" + fileName);
-}
-
-std::string TileCache::cacheDirName(const bool useEditingCache)
-{
- return (useEditingCache ? _editCacheDir : _persCacheDir);
+ Log::warn("Removing file: " + _cacheDir + "/" + fileName);
+ Util::removeFile(_cacheDir + "/" + fileName);
}
std::string TileCache::cacheFileName(int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, int tileHeight)
@@ -439,7 +331,7 @@ bool TileCache::intersectsTile(const std::string& fileName, int part, int x, int
Timestamp TileCache::getLastModified()
{
- std::fstream modTimeFile(_rootCacheDir + "/modtime.txt", std::ios::in);
+ std::fstream modTimeFile(_cacheDir + "/modtime.txt", std::ios::in);
if (!modTimeFile.is_open())
return 0;
@@ -453,7 +345,7 @@ Timestamp TileCache::getLastModified()
void TileCache::saveLastModified(const Timestamp& timestamp)
{
- std::fstream modTimeFile(_rootCacheDir + "/modtime.txt", std::ios::out);
+ std::fstream modTimeFile(_cacheDir + "/modtime.txt", std::ios::out);
modTimeFile << timestamp.raw() << std::endl;
modTimeFile.close();
}
diff --git a/loolwsd/TileCache.hpp b/loolwsd/TileCache.hpp
index cc4f746..7c6c279 100644
--- a/loolwsd/TileCache.hpp
+++ b/loolwsd/TileCache.hpp
@@ -19,13 +19,6 @@
#include <Poco/Timestamp.h>
/** Handles the cache for tiles of one document.
-
-The cache consists of 2 cache directories:
-
- * persistent - that always represents the document as is saved
- * editing - that represents the document in the current state (with edits)
-
-The editing cache is cleared on startup, and copied to the persistent on each save.
*/
class MasterProcessSession;
@@ -45,7 +38,7 @@ public:
/// When the docURL is a non-file:// url, the timestamp has to be provided by the caller.
/// For file:// url's, it's ignored.
/// When it is missing for non-file:// url, it is assumed the document must be read, and no cached value used.
- TileCache(const std::string& docURL, const Poco::Timestamp& modifiedTime, const std::string& rootCacheDir);
+ TileCache(const std::string& docURL, const Poco::Timestamp& modifiedTime, const std::string& cacheDir);
~TileCache();
TileCache(const TileCache&) = delete;
@@ -61,16 +54,13 @@ public:
std::unique_ptr<std::fstream> lookupTile(int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, int tileHeight);
void saveTile(int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, int tileHeight, const char *data, size_t size);
- std::string getTextFile(std::string fileName);
-
- /// Notify the cache that the document was saved - to copy tiles from the Editing cache to Persistent.
- void documentSaved();
+ std::string getTextFile(const std::string& fileName);
- /// Notify whether we need to use the Editing cache.
- void setEditing(bool editing);
+ // Save some text into a file in the cache directory
+ void saveTextFile(const std::string& text, const std::string& fileName);
- // The parameter is a message
- void saveTextFile(const std::string& text, std::string fileName);
+ // Set the unsaved-changes state, used for sanity checks, ideally not needed
+ void setUnsavedChanges(bool state);
// Saves a font / style / etc rendering
// The dir parameter should be the type of rendering, like "font", "style", etc
@@ -83,13 +73,13 @@ public:
void invalidateTiles(int part, int x, int y, int width, int height);
- // Removes the given file from both editing and persistent cache
+ // Removes the given file from the cache
void removeFile(const std::string& fileName);
-private:
- /// Path of the (sub-)cache dir, the parameter specifies which (sub-)cache to use.
- std::string cacheDirName(bool useEditingCache);
+ /// Store the timestamp to modtime.txt.
+ void saveLastModified(const Poco::Timestamp& timestamp);
+private:
std::string cacheFileName(int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, int tileHeight);
bool parseCacheFileName(const std::string& fileName, int& part, int& width, int& height, int& tilePosX, int& tilePosY, int& tileWidth, int& tileHeight);
@@ -99,22 +89,9 @@ private:
/// Load the timestamp from modtime.txt.
Poco::Timestamp getLastModified();
- /// Store the timestamp to modtime.txt.
- void saveLastModified(const Poco::Timestamp& timestamp);
-
const std::string _docURL;
- const std::string _rootCacheDir;
- const std::string _persCacheDir;
- const std::string _editCacheDir;
-
- /// The document is being edited.
- bool _isEditing;
-
- /// We have some unsaved changes => use the Editing cache.
- bool _hasUnsavedChanges;
- /// Set of tiles that we want to remove from the Persistent cache on the next save.
- std::set<std::string> _toBeRemoved;
+ const std::string _cacheDir;
std::mutex _cacheMutex;
diff --git a/loolwsd/loolwsd.xml.in b/loolwsd/loolwsd.xml.in
index d44d3ee..0916f01 100644
--- a/loolwsd/loolwsd.xml.in
+++ b/loolwsd/loolwsd.xml.in
@@ -1,6 +1,6 @@
<config>
- <tile_cache_path desc="Path to a directory where to keep the persistent tile cache." type="path" relative="false" default="@LOOLWSD_CACHEDIR@"></tile_cache_path>
+ <tile_cache_path desc="Path to a directory where to keep the tile cache." type="path" relative="false" default="@LOOLWSD_CACHEDIR@"></tile_cache_path>
<sys_template_path desc="Path to a template tree with shared libraries etc to be used as source for chroot jails for child processes." type="path" relative="true" default="systemplate"></sys_template_path>
<lo_template_path desc="Path to a LibreOffice installation tree to be copied (linked) into the jails for child processes. Should be on the same file system as systemplate." type="path" relative="false" default="/opt/collaboraoffice5.0"></lo_template_path>
<child_root_path desc="Path to the directory under which the chroot jails for the child processes will be created. Should be on the same file system as systemplate and lotemplate. Must be an empty directory." type="path" relative="true" default="jails"></child_root_path>
commit b0cfa350187c024503392cd06636c78de92be00c
Author: Tor Lillqvist <tml at collabora.com>
Date: Fri Apr 22 13:26:32 2016 +0300
Remove accidental superfluous indentation
diff --git a/loolwsd/test/httpwstest.cpp b/loolwsd/test/httpwstest.cpp
index f915d79..3b888c8 100644
--- a/loolwsd/test/httpwstest.cpp
+++ b/loolwsd/test/httpwstest.cpp
@@ -1001,43 +1001,43 @@ void HTTPWSTest::testImpressPartCountChanged()
void HTTPWSTest::testSimultaneousTilesRenderedJustOnce()
{
- const std::string documentPath = Util::getTempFilePath(TDOC, "hello.odt");
- const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString();
+ const std::string documentPath = Util::getTempFilePath(TDOC, "hello.odt");
+ const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString();
- Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
- Poco::Net::WebSocket socket1 = *connectLOKit(request, _response);
- sendTextFrame(socket1, "load url=" + documentURL);
+ Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
+ Poco::Net::WebSocket socket1 = *connectLOKit(request, _response);
+ sendTextFrame(socket1, "load url=" + documentURL);
- Poco::Net::WebSocket socket2 = *connectLOKit(request, _response);
- sendTextFrame(socket2, "load url=" + documentURL);
+ Poco::Net::WebSocket socket2 = *connectLOKit(request, _response);
+ sendTextFrame(socket2, "load url=" + documentURL);
- sendTextFrame(socket1, "tile part=42 width=400 height=400 tileposx=1000 tileposy=2000 tilewidth=3000 tileheight=3000");
- sendTextFrame(socket2, "tile part=42 width=400 height=400 tileposx=1000 tileposy=2000 tilewidth=3000 tileheight=3000");
+ sendTextFrame(socket1, "tile part=42 width=400 height=400 tileposx=1000 tileposy=2000 tilewidth=3000 tileheight=3000");
+ sendTextFrame(socket2, "tile part=42 width=400 height=400 tileposx=1000 tileposy=2000 tilewidth=3000 tileheight=3000");
- std::string response1;
- getResponseMessage(socket1, "tile:", response1, true);
- CPPUNIT_ASSERT_MESSAGE("did not receive a tile: message as expected", !response1.empty());
+ std::string response1;
+ getResponseMessage(socket1, "tile:", response1, true);
+ CPPUNIT_ASSERT_MESSAGE("did not receive a tile: message as expected", !response1.empty());
- std::string response2;
- getResponseMessage(socket2, "tile:", response2, true);
- CPPUNIT_ASSERT_MESSAGE("did not receive a tile: message as expected", !response2.empty());
+ std::string response2;
+ getResponseMessage(socket2, "tile:", response2, true);
+ CPPUNIT_ASSERT_MESSAGE("did not receive a tile: message as expected", !response2.empty());
- if (!response1.empty() && !response2.empty())
- {
- Poco::StringTokenizer tokens1(response1, " ");
- std::string renderId1;
- LOOLProtocol::getTokenString(tokens1, "renderid", renderId1);
- Poco::StringTokenizer tokens2(response2, " ");
- std::string renderId2;
- LOOLProtocol::getTokenString(tokens2, "renderid", renderId2);
-
- CPPUNIT_ASSERT(renderId1 == renderId2 ||
- (renderId1 == "cached" && renderId2 != "cached") ||
- (renderId1 != "cached" && renderId2 == "cached"));
- }
+ if (!response1.empty() && !response2.empty())
+ {
+ Poco::StringTokenizer tokens1(response1, " ");
+ std::string renderId1;
+ LOOLProtocol::getTokenString(tokens1, "renderid", renderId1);
+ Poco::StringTokenizer tokens2(response2, " ");
+ std::string renderId2;
+ LOOLProtocol::getTokenString(tokens2, "renderid", renderId2);
+
+ CPPUNIT_ASSERT(renderId1 == renderId2 ||
+ (renderId1 == "cached" && renderId2 != "cached") ||
+ (renderId1 != "cached" && renderId2 == "cached"));
+ }
- socket1.shutdown();
- socket2.shutdown();
+ socket1.shutdown();
+ socket2.shutdown();
}
void HTTPWSTest::testNoExtraLoolKitsLeft()
commit 4aaf70bf8e487866a7eed396127f2b41e19eb026
Author: Tor Lillqvist <tml at collabora.com>
Date: Fri Apr 22 13:24:35 2016 +0300
The logging goes to stderr, not stdout
Check whether stderr goes to a terminal, not whether stdout does.
diff --git a/loolwsd/Log.cpp b/loolwsd/Log.cpp
index 9038a78..930268b 100644
--- a/loolwsd/Log.cpp
+++ b/loolwsd/Log.cpp
@@ -110,7 +110,7 @@ namespace Log
assert (sizeof (LogPrefix) > strlen(oss.str().c_str()) + 1);
strncpy(LogPrefix, oss.str().c_str(), sizeof(LogPrefix));
- auto channel = (isatty(fileno(stdout)) || std::getenv("LOOL_LOGCOLOR")
+ auto channel = (isatty(fileno(stderr)) || std::getenv("LOOL_LOGCOLOR")
? static_cast<Poco::Channel*>(new Poco::ColorConsoleChannel())
: static_cast<Poco::Channel*>(new Poco::ConsoleChannel()));
auto& logger = Poco::Logger::create(Source.name, channel, Poco::Message::PRIO_TRACE);
More information about the Libreoffice-commits
mailing list