loolwsd/DocumentBroker.cpp | 5 +- loolwsd/Storage.hpp | 9 +++-- loolwsd/TileCache.cpp | 81 ++++++++++----------------------------------- loolwsd/TileCache.hpp | 6 --- 4 files changed, 29 insertions(+), 72 deletions(-)
New commits: commit b4a4c45a36b73368cacd989a4b240021afcddb35 Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk> Date: Sat Mar 26 10:42:15 2016 -0400 loolwsd: Storage gets last modified time and simplified TileCache construction Change-Id: I4a7e7b941c136b59ffd7d935310d37d73ac4ec63 Reviewed-on: https://gerrit.libreoffice.org/23540 Reviewed-by: Ashod Nakashian <ashnak...@gmail.com> Tested-by: Ashod Nakashian <ashnak...@gmail.com> diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp index 7ee2d50..d36998f 100644 --- a/loolwsd/DocumentBroker.cpp +++ b/loolwsd/DocumentBroker.cpp @@ -104,8 +104,9 @@ bool DocumentBroker::load(const std::string& jailId) Log::info("jailPath: " + jailPath.toString() + ", jailRoot: " + jailRoot); - const std::string timestamp = ""; //FIXME: Should come from load options. - _tileCache.reset(new TileCache(_uriPublic.toString(), timestamp, _cacheRoot)); + auto storage = createStorage("", "", _uriPublic); + const auto fileInfo = storage->getFileInfo(_uriPublic); + _tileCache.reset(new TileCache(_uriPublic.toString(), fileInfo.ModifiedTime, _cacheRoot)); _storage = createStorage(jailRoot, jailPath.toString(), _uriPublic); diff --git a/loolwsd/Storage.hpp b/loolwsd/Storage.hpp index f33084b..1f92541 100644 --- a/loolwsd/Storage.hpp +++ b/loolwsd/Storage.hpp @@ -33,6 +33,7 @@ public: { public: std::string Filename; + Poco::Timestamp ModifiedTime; size_t Size; }; @@ -110,8 +111,9 @@ public: const auto path = uri.getPath(); Log::debug("Getting info for local uri [" + uri.toString() + "], path [" + path + "]."); const auto filename = Poco::Path(path).getFileName(); + const auto lastModified = Poco::File(path).getLastModified(); const auto size = Poco::File(path).getSize(); - return FileInfo({filename, size}); + return FileInfo({filename, lastModified, size}); } std::string loadStorageFileToLocal() override @@ -227,7 +229,8 @@ public: size = std::stoul (object->get("Size").toString(), nullptr, 0); } - return FileInfo({filename, size}); + // WOPI doesn't support file last modified time. + return FileInfo({filename, Poco::Timestamp(), size}); } /// uri format: http://server/<...>/wopi*/files/<id>/content @@ -331,7 +334,7 @@ public: Log::debug("Getting info for webdav uri [" + uri.toString() + "]."); (void)uri; assert(!"Not Implemented!"); - return FileInfo({"bazinga", 0}); + return FileInfo({"bazinga", Poco::Timestamp(), 0}); } std::string loadStorageFileToLocal() override diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp index 58d0900..bed7681 100644 --- a/loolwsd/TileCache.cpp +++ b/loolwsd/TileCache.cpp @@ -44,7 +44,7 @@ using Poco::URI; using namespace LOOLProtocol; TileCache::TileCache(const std::string& docURL, - const std::string& timestamp, + const Poco::Timestamp& modifiedTime, const std::string& rootCacheDir) : _docURL(docURL), _rootCacheDir(rootCacheDir), @@ -54,7 +54,24 @@ TileCache::TileCache(const std::string& docURL, _hasUnsavedChanges(false) { Log::info("TileCache ctor."); - setup(timestamp); + const bool cleanEverything = (getLastModified() < modifiedTime); + if (cleanEverything) + { + // document changed externally, clean up everything + Util::removeFile(_rootCacheDir, true); + Log::info("Completely cleared cache: " + _rootCacheDir); + } + else + { + // remove only the Editing cache + Util::removeFile(_editCacheDir, true); + Log::info("Cleared the editing cache: " + _editCacheDir); + } + + File cacheDir(_rootCacheDir); + cacheDir.createDirectories(); + + saveLastModified(modifiedTime); } TileCache::~TileCache() @@ -374,64 +391,4 @@ void TileCache::saveLastModified(const Poco::Timestamp& timestamp) modTimeFile.close(); } -void TileCache::setup(const std::string& timestamp) -{ - bool cleanEverything = true; - std::string filePath; - Timestamp lastModified; - - try - { - URI uri(_docURL); - if (uri.getScheme() == "" || - uri.getScheme() == "file") - { - filePath = uri.getPath(); - } - } - catch (SyntaxException& e) - { - } - - if (!filePath.empty() && File(filePath).exists() && File(filePath).isFile()) - { - // for files, always use the real path - lastModified = File(filePath).getLastModified(); - cleanEverything = (getLastModified() < lastModified); - } - else if (!timestamp.empty()) - { - // otherwise try the timestamp provided by the caller - Timestamp::TimeVal lastTimeVal; - std::istringstream(timestamp) >> lastTimeVal; - lastModified = lastTimeVal; - Log::info("Timestamp provided externally: " + timestamp); - - cleanEverything = (getLastModified() < Timestamp(lastModified)); - } - else - { - // when no timestamp, and non-file, assume 'now' - lastModified = Timestamp(); - } - - if (cleanEverything) - { - // document changed externally, clean up everything - Util::removeFile(_rootCacheDir, true); - Log::info("Completely cleared cache: " + _rootCacheDir); - } - else - { - // remove only the Editing cache - Util::removeFile(_editCacheDir, true); - Log::info("Cleared the editing cache: " + _editCacheDir); - } - - File cacheDir(_rootCacheDir); - cacheDir.createDirectories(); - - saveLastModified(lastModified); -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/loolwsd/TileCache.hpp b/loolwsd/TileCache.hpp index aad3e8d..bb25d62 100644 --- a/loolwsd/TileCache.hpp +++ b/loolwsd/TileCache.hpp @@ -34,7 +34,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 std::string& timestamp, const std::string& rootCacheDir); + TileCache(const std::string& docURL, const Poco::Timestamp& modifiedTime, const std::string& rootCacheDir); ~TileCache(); TileCache(const TileCache&) = delete; @@ -82,10 +82,6 @@ private: /// Store the timestamp to modtime.txt. void saveLastModified(const Poco::Timestamp& timestamp); - /// Create or cleanup the cache directory. - /// For non-file:// protocols, the timestamp has to be provided externally. - void setup(const std::string& timestamp); - private: const std::string _docURL; const std::string _rootCacheDir; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits