[Libreoffice-commits] online.git: 2 commits - loolwsd/LOOLWSD.cpp loolwsd/MasterProcessSession.cpp loolwsd/TileCache.cpp loolwsd/Util.hpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Fri Dec 25 19:59:38 PST 2015
loolwsd/LOOLWSD.cpp | 5 ++---
loolwsd/MasterProcessSession.cpp | 8 +++++---
loolwsd/TileCache.cpp | 35 +++++++++++++++--------------------
loolwsd/Util.hpp | 25 +++++++++++++++++++++++++
4 files changed, 47 insertions(+), 26 deletions(-)
New commits:
commit 03fa56f9de09bde18c8c1abaa677191a01b71e9a
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Fri Dec 25 22:42:39 2015 -0500
loolwsd: load document immediately upon handshake
Change-Id: If750ae0a94258048c99f6dd47f7abb3a59660c6f
Reviewed-on: https://gerrit.libreoffice.org/20950
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index 8430efc..3766111 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -388,6 +388,10 @@ bool MasterProcessSession::loadDocument(const char* /*buffer*/, int /*length*/,
_tileCache.reset(new TileCache(_docURL, timestamp));
+ // Finally, wait for the Child to connect to Master,
+ // link the document in jail and dispatch load to child.
+ dispatchChild();
+
return true;
}
commit d26944b71507473833ea9d27c8285e0384e4eb0e
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Fri Dec 25 20:11:47 2015 -0500
loolwsd: safely remove files and directories
Change-Id: Ie017a9da720a470a6b8ed340bd4ea5ffc279cf4b
Reviewed-on: https://gerrit.libreoffice.org/20949
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index b0273b4..8b100d4 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -368,7 +368,7 @@ public:
// Clean up the temporary directory the HTMLForm ctor created.
Path tempDirectory(fromPath);
tempDirectory.setFileName("");
- File(tempDirectory).remove(/*recursive=*/true);
+ Util::removeFile(tempDirectory, /*recursive=*/true);
}
else if (tokens.count() >= 2 && tokens[1] == "insertfile")
{
@@ -413,8 +413,7 @@ public:
if (form.has("mime_type"))
mimeType = form.get("mime_type");
response.sendFile(filePath, mimeType);
- File dir(dirPath);
- dir.remove(true);
+ Util::removeFile(dirPath, true);
}
else
{
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index f7dfa9b..8430efc 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -615,9 +615,7 @@ void MasterProcessSession::dispatchChild()
}
// cleanup potential leftovers from the last time
- File aToCleanup(aDstFile);
- if (aToCleanup.exists())
- aToCleanup.remove();
+ Util::removeFile(aDstFile);
#ifdef __linux
Log::info("Linking " + aSrcFile.toString() + " to " + aDstFile.toString());
diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp
index 938552c..21673c1 100644
--- a/loolwsd/TileCache.cpp
+++ b/loolwsd/TileCache.cpp
@@ -147,7 +147,7 @@ void TileCache::documentSaved()
// first remove the invalidated tiles from the Persistent cache
std::string persistentDirName = cacheDirName(false);
for (const auto& it : _toBeRemoved)
- File(persistentDirName + "/" + it).remove();
+ Util::removeFile(persistentDirName + "/" + it);
_cacheMutex.lock();
// then move the new tiles from the Editing cache to Persistent
@@ -228,7 +228,7 @@ void TileCache::invalidateTiles(int part, int x, int y, int width, int height)
const std::string fileName = tileIterator.path().getFileName();
if (intersectsTile(fileName, part, x, y, width, height))
{
- File(tileIterator.path()).remove();
+ Util::removeFile(tileIterator.path());
}
}
_cacheMutex.unlock();
@@ -392,27 +392,22 @@ void TileCache::setup(const std::string& timestamp)
lastModified = Timestamp();
}
- File cacheDir(toplevelCacheDirName());
- if (cacheDir.exists())
+ if (cleanEverything)
{
- if (cleanEverything)
- {
- // document changed externally, clean up everything
- cacheDir.remove(true);
- Log::info("Completely cleared cache: " + toplevelCacheDirName());
- }
- else
- {
- // remove only the Editing cache
- File editingCacheDir(cacheDirName(true));
- if (editingCacheDir.exists())
- {
- editingCacheDir.remove(true);
- Log::info("Cleared the editing cache: " + cacheDirName(true));
- }
- }
+ // document changed externally, clean up everything
+ const auto path = toplevelCacheDirName();
+ Util::removeFile(path, true);
+ Log::info("Completely cleared cache: " + path);
+ }
+ else
+ {
+ // remove only the Editing cache
+ const auto path = cacheDirName(true);
+ Util::removeFile(path, true);
+ Log::info("Cleared the editing cache: " + path);
}
+ File cacheDir(toplevelCacheDirName());
cacheDir.createDirectories();
saveLastModified(lastModified);
diff --git a/loolwsd/Util.hpp b/loolwsd/Util.hpp
index e57c100..fa79b33 100644
--- a/loolwsd/Util.hpp
+++ b/loolwsd/Util.hpp
@@ -13,6 +13,8 @@
#include <string>
#include <sstream>
+#include <Poco/File.h>
+#include <Poco/Path.h>
#include <Poco/Net/WebSocket.h>
#include <Poco/Logger.h>
@@ -44,6 +46,29 @@ namespace Util
ssize_t readFIFO(int nPipe, char* pBuffer, ssize_t nSize);
ssize_t readMessage(int nPipe, char* pBuffer, ssize_t nSize);
+
+ /// Safely remove a file or directory.
+ /// Supresses exception when the file is already removed.
+ /// This can happen when there is a race (unavoidable) or when
+ /// we don't care to check before we remove (when no race exists).
+ inline
+ void removeFile(const std::string& path, const bool recursive = false)
+ {
+ try
+ {
+ Poco::File(path).remove(recursive);
+ }
+ catch (const std::exception&)
+ {
+ // Already removed, nothing more to do.
+ }
+ }
+
+ inline
+ void removeFile(const Poco::Path& path, const bool recursive = false)
+ {
+ removeFile(path.toString(), recursive);
+ }
};
//TODO: Move to own file.
More information about the Libreoffice-commits
mailing list