2015-04-13 04:09:02 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
2015-03-12 09:18:35 -05:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2015-05-28 04:53:14 -05:00
|
|
|
#include <cassert>
|
2015-05-29 00:39:21 -05:00
|
|
|
#include <climits>
|
2015-05-28 10:39:05 -05:00
|
|
|
#include <cstdio>
|
2015-03-12 09:18:35 -05:00
|
|
|
#include <fstream>
|
|
|
|
#include <iostream>
|
|
|
|
#include <memory>
|
2015-08-04 13:37:05 -05:00
|
|
|
#include <sstream>
|
2015-05-05 06:57:51 -05:00
|
|
|
#include <string>
|
2015-03-12 09:18:35 -05:00
|
|
|
|
2015-05-29 00:49:49 -05:00
|
|
|
#include <Poco/DigestEngine.h>
|
2015-05-28 10:39:05 -05:00
|
|
|
#include <Poco/DirectoryIterator.h>
|
2015-05-29 04:23:57 -05:00
|
|
|
#include <Poco/Exception.h>
|
2015-03-12 09:18:35 -05:00
|
|
|
#include <Poco/File.h>
|
|
|
|
#include <Poco/Path.h>
|
|
|
|
#include <Poco/SHA1Engine.h>
|
2015-05-28 04:53:14 -05:00
|
|
|
#include <Poco/StringTokenizer.h>
|
2015-05-29 00:49:49 -05:00
|
|
|
#include <Poco/Timestamp.h>
|
2015-05-29 04:23:57 -05:00
|
|
|
#include <Poco/URI.h>
|
2015-08-04 13:37:05 -05:00
|
|
|
#include <Poco/Util/Application.h>
|
2015-03-12 09:18:35 -05:00
|
|
|
|
2015-06-04 09:07:49 -05:00
|
|
|
#include "LOOLWSD.hpp"
|
2015-07-21 06:53:53 -05:00
|
|
|
#include "LOOLProtocol.hpp"
|
2015-03-12 09:18:35 -05:00
|
|
|
#include "TileCache.hpp"
|
2015-08-04 13:37:05 -05:00
|
|
|
#include "Util.hpp"
|
2015-03-12 09:18:35 -05:00
|
|
|
|
2015-05-29 00:49:49 -05:00
|
|
|
using Poco::DigestEngine;
|
|
|
|
using Poco::DirectoryIterator;
|
|
|
|
using Poco::File;
|
|
|
|
using Poco::SHA1Engine;
|
|
|
|
using Poco::StringTokenizer;
|
2015-05-29 04:23:57 -05:00
|
|
|
using Poco::SyntaxException;
|
2015-05-29 00:49:49 -05:00
|
|
|
using Poco::Timestamp;
|
2015-05-29 04:23:57 -05:00
|
|
|
using Poco::URI;
|
2015-08-04 13:37:05 -05:00
|
|
|
using Poco::Util::Application;
|
2015-05-29 00:49:49 -05:00
|
|
|
|
2015-07-21 06:53:53 -05:00
|
|
|
using namespace LOOLProtocol;
|
|
|
|
|
2015-08-04 13:37:05 -05:00
|
|
|
TileCache::TileCache(const std::string& docURL, const std::string& timestamp) :
|
2015-06-24 15:05:49 -05:00
|
|
|
_docURL(docURL),
|
|
|
|
_isEditing(false),
|
|
|
|
_hasUnsavedChanges(false)
|
2015-03-12 18:34:42 -05:00
|
|
|
{
|
2015-08-04 13:37:05 -05:00
|
|
|
setup(timestamp);
|
2015-03-12 09:18:35 -05:00
|
|
|
}
|
|
|
|
|
2015-04-27 13:24:05 -05:00
|
|
|
std::unique_ptr<std::fstream> TileCache::lookupTile(int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, int tileHeight)
|
2015-03-12 09:18:35 -05:00
|
|
|
{
|
2015-06-24 15:05:49 -05:00
|
|
|
std::string cachedName = cacheFileName(part, width, height, tilePosX, tilePosY, tileWidth, tileHeight);
|
2015-03-12 18:34:42 -05:00
|
|
|
|
2015-06-24 15:05:49 -05:00
|
|
|
if (_hasUnsavedChanges)
|
|
|
|
{
|
|
|
|
// try the Editing cache first
|
|
|
|
std::string dirName = cacheDirName(true);
|
|
|
|
std::string fileName = + "/" + cachedName;
|
|
|
|
File dir(dirName);
|
|
|
|
|
|
|
|
if (dir.exists() && dir.isDirectory() && File(fileName).exists())
|
|
|
|
{
|
|
|
|
std::unique_ptr<std::fstream> result(new std::fstream(fileName, std::ios::in));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// skip tiles scheduled for removal from the Persistent cache (on save)
|
|
|
|
if (_toBeRemoved.find(cachedName) != _toBeRemoved.end())
|
2015-03-12 18:34:42 -05:00
|
|
|
return nullptr;
|
2015-03-12 09:18:35 -05:00
|
|
|
|
2015-06-24 15:05:49 -05:00
|
|
|
// default to the content of the Persistent cache
|
|
|
|
std::string dirName = cacheDirName(false);
|
|
|
|
File dir(dirName);
|
|
|
|
|
|
|
|
if (!dir.exists() || !dir.isDirectory())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
std::string fileName = dirName + "/" + cachedName;
|
2015-03-12 18:34:42 -05:00
|
|
|
|
|
|
|
std::unique_ptr<std::fstream> result(new std::fstream(fileName, std::ios::in));
|
2015-03-12 09:18:35 -05:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-04-27 13:24:05 -05:00
|
|
|
void TileCache::saveTile(int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, int tileHeight, const char *data, size_t size)
|
2015-03-12 09:18:35 -05:00
|
|
|
{
|
2015-06-24 15:05:49 -05:00
|
|
|
if (_isEditing && !_hasUnsavedChanges)
|
|
|
|
_hasUnsavedChanges = true;
|
|
|
|
|
|
|
|
std::string dirName = cacheDirName(_hasUnsavedChanges);
|
2015-03-12 09:18:35 -05:00
|
|
|
|
2015-05-29 00:49:49 -05:00
|
|
|
File(dirName).createDirectories();
|
2015-03-12 09:18:35 -05:00
|
|
|
|
2015-04-27 13:24:05 -05:00
|
|
|
std::string fileName = dirName + "/" + cacheFileName(part, width, height, tilePosX, tilePosY, tileWidth, tileHeight);
|
2015-03-13 07:17:51 -05:00
|
|
|
|
2015-03-12 18:34:42 -05:00
|
|
|
std::fstream outStream(fileName, std::ios::out);
|
2015-03-12 09:18:35 -05:00
|
|
|
outStream.write(data, size);
|
|
|
|
outStream.close();
|
2015-03-12 18:34:42 -05:00
|
|
|
}
|
|
|
|
|
2015-08-18 13:01:05 -05:00
|
|
|
std::string TileCache::getTextFile(std::string fileName)
|
2015-03-13 07:17:51 -05:00
|
|
|
{
|
2015-12-09 22:51:11 -06:00
|
|
|
const auto textFile = std::string("/" + fileName);
|
2015-06-24 15:05:49 -05:00
|
|
|
|
|
|
|
std::string dirName = cacheDirName(false);
|
|
|
|
if (_hasUnsavedChanges)
|
|
|
|
{
|
2015-08-18 13:01:05 -05:00
|
|
|
// try the Editing cache first, and prefer it if it exists
|
2015-06-24 15:05:49 -05:00
|
|
|
std::string editingDirName = cacheDirName(true);
|
|
|
|
File dir(editingDirName);
|
|
|
|
|
2015-08-18 13:01:05 -05:00
|
|
|
File text(editingDirName + textFile);
|
|
|
|
if (dir.exists() && dir.isDirectory() && text.exists() && !text.isDirectory())
|
2015-06-24 15:05:49 -05:00
|
|
|
dirName = editingDirName;
|
|
|
|
}
|
2015-03-13 07:17:51 -05:00
|
|
|
|
2015-05-29 00:49:49 -05:00
|
|
|
if (!File(dirName).exists() || !File(dirName).isDirectory())
|
2015-03-16 14:08:07 -05:00
|
|
|
return "";
|
2015-03-13 07:17:51 -05:00
|
|
|
|
2015-08-18 13:01:05 -05:00
|
|
|
fileName = dirName + textFile;
|
|
|
|
std::fstream textStream(fileName, std::ios::in);
|
|
|
|
if (!textStream.is_open())
|
2015-03-13 07:17:51 -05:00
|
|
|
return "";
|
2015-03-16 14:08:07 -05:00
|
|
|
|
2015-03-13 07:17:51 -05:00
|
|
|
std::vector<char> result;
|
2015-08-18 13:01:05 -05:00
|
|
|
textStream.seekg(0, std::ios_base::end);
|
|
|
|
std::streamsize size = textStream.tellg();
|
2015-03-13 07:17:51 -05:00
|
|
|
result.resize(size);
|
2015-08-18 13:01:05 -05:00
|
|
|
textStream.seekg(0, std::ios_base::beg);
|
|
|
|
textStream.read(result.data(), size);
|
|
|
|
textStream.close();
|
2015-03-13 07:17:51 -05:00
|
|
|
|
|
|
|
if (result[result.size()-1] == '\n')
|
|
|
|
result.resize(result.size() - 1);
|
2015-03-16 14:08:07 -05:00
|
|
|
|
2015-03-13 07:17:51 -05:00
|
|
|
return std::string(result.data(), result.size());
|
|
|
|
}
|
|
|
|
|
2015-06-24 15:05:49 -05:00
|
|
|
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();
|
|
|
|
|
2015-08-12 07:31:02 -05:00
|
|
|
_cacheMutex.lock();
|
2015-06-24 15:05:49 -05:00
|
|
|
// then move the new tiles from the Editing cache to Persistent
|
|
|
|
for (auto tileIterator = DirectoryIterator(cacheDirName(true)); tileIterator != DirectoryIterator(); ++tileIterator)
|
|
|
|
tileIterator->moveTo(persistentDirName);
|
2015-08-12 07:31:02 -05:00
|
|
|
_cacheMutex.unlock();
|
2015-06-24 15:05:49 -05:00
|
|
|
|
|
|
|
// update status
|
|
|
|
_toBeRemoved.clear();
|
|
|
|
_hasUnsavedChanges = false;
|
2015-08-04 13:37:05 -05:00
|
|
|
|
|
|
|
// FIXME should we take the exact time of the file for the local files?
|
|
|
|
saveLastModified(Timestamp());
|
2015-06-24 15:05:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void TileCache::setEditing(bool editing)
|
|
|
|
{
|
|
|
|
_isEditing = editing;
|
|
|
|
}
|
|
|
|
|
2015-08-18 13:01:05 -05:00
|
|
|
void TileCache::saveTextFile(const std::string& text, std::string fileName)
|
2015-03-13 07:17:51 -05:00
|
|
|
{
|
2015-09-30 09:17:03 -05:00
|
|
|
std::string dirName = cacheDirName(_isEditing);
|
2015-03-13 07:17:51 -05:00
|
|
|
|
2015-05-29 00:49:49 -05:00
|
|
|
File(dirName).createDirectories();
|
2015-03-13 07:17:51 -05:00
|
|
|
|
2015-08-18 13:01:05 -05:00
|
|
|
StringTokenizer tokens(text, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
|
2015-05-28 04:53:14 -05:00
|
|
|
|
2015-08-18 13:01:05 -05:00
|
|
|
fileName = dirName + "/" + fileName;
|
|
|
|
std::fstream textStream(fileName, std::ios::out);
|
2015-05-28 04:53:14 -05:00
|
|
|
|
2015-08-18 13:01:05 -05:00
|
|
|
if (!textStream.is_open())
|
2015-03-13 07:17:51 -05:00
|
|
|
return;
|
|
|
|
|
2015-08-18 13:01:05 -05:00
|
|
|
textStream << text << std::endl;
|
|
|
|
textStream.close();
|
2015-03-13 07:17:51 -05:00
|
|
|
}
|
|
|
|
|
2015-11-27 08:12:44 -06:00
|
|
|
void TileCache::saveRendering(const std::string& name, const std::string& dir, const char *data, size_t size)
|
|
|
|
{
|
|
|
|
// can fonts be invalidated?
|
|
|
|
std::string dirName = cacheDirName(false) + "/" + dir;
|
|
|
|
|
|
|
|
File(dirName).createDirectories();
|
|
|
|
|
|
|
|
std::string fileName = dirName + "/" + name;
|
|
|
|
|
|
|
|
std::fstream outStream(fileName, std::ios::out);
|
|
|
|
outStream.write(data, size);
|
|
|
|
outStream.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<std::fstream> TileCache::lookupRendering(const std::string& name, const std::string& dir)
|
|
|
|
{
|
|
|
|
std::string dirName = cacheDirName(false) + "/" + dir;
|
|
|
|
std::string fileName = dirName + "/" + name;
|
|
|
|
File directory(dirName);
|
|
|
|
|
|
|
|
if (directory.exists() && directory.isDirectory() && File(fileName).exists())
|
|
|
|
{
|
|
|
|
std::unique_ptr<std::fstream> result(new std::fstream(fileName, std::ios::in));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-05-28 10:39:05 -05:00
|
|
|
void TileCache::invalidateTiles(int part, int x, int y, int width, int height)
|
|
|
|
{
|
2015-06-24 15:05:49 -05:00
|
|
|
// in the Editing cache, remove immediately
|
|
|
|
std::string editingDirName = cacheDirName(true);
|
|
|
|
File editingDir(editingDirName);
|
|
|
|
if (editingDir.exists() && editingDir.isDirectory())
|
2015-05-28 10:39:05 -05:00
|
|
|
{
|
2015-08-12 07:31:02 -05:00
|
|
|
_cacheMutex.lock();
|
2015-06-24 15:05:49 -05:00
|
|
|
for (auto tileIterator = DirectoryIterator(editingDir); tileIterator != DirectoryIterator(); ++tileIterator)
|
2015-05-28 10:39:05 -05:00
|
|
|
{
|
2015-06-24 15:05:49 -05:00
|
|
|
std::string fileName = tileIterator.path().getFileName();
|
|
|
|
if (intersectsTile(fileName, part, x, y, width, height))
|
2015-05-28 10:39:05 -05:00
|
|
|
{
|
2015-06-24 15:05:49 -05:00
|
|
|
File(tileIterator.path()).remove();
|
2015-05-28 10:39:05 -05:00
|
|
|
}
|
|
|
|
}
|
2015-08-12 07:31:02 -05:00
|
|
|
_cacheMutex.unlock();
|
2015-05-28 10:39:05 -05:00
|
|
|
}
|
|
|
|
|
2015-06-24 15:05:49 -05:00
|
|
|
// in the Persistent cache, add to _toBeRemoved for removal on save
|
|
|
|
std::string persistentDirName = cacheDirName(false);
|
|
|
|
File persistentDir(persistentDirName);
|
|
|
|
if (persistentDir.exists() && persistentDir.isDirectory())
|
|
|
|
{
|
|
|
|
for (auto tileIterator = DirectoryIterator(persistentDir); tileIterator != DirectoryIterator(); ++tileIterator)
|
|
|
|
{
|
|
|
|
std::string fileName = tileIterator.path().getFileName();
|
|
|
|
if (_toBeRemoved.find(fileName) == _toBeRemoved.end() && intersectsTile(fileName, part, x, y, width, height))
|
|
|
|
{
|
|
|
|
_toBeRemoved.insert(fileName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-28 10:39:05 -05:00
|
|
|
}
|
|
|
|
|
2015-07-21 06:53:53 -05:00
|
|
|
void TileCache::invalidateTiles(const std::string& tiles)
|
2015-05-28 10:39:05 -05:00
|
|
|
{
|
2015-05-29 00:49:49 -05:00
|
|
|
StringTokenizer tokens(tiles, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
|
2015-05-28 10:39:05 -05:00
|
|
|
|
2015-05-28 15:22:27 -05:00
|
|
|
assert(tokens[0] == "invalidatetiles:");
|
2015-05-28 10:39:05 -05:00
|
|
|
|
2015-05-29 00:39:21 -05:00
|
|
|
if (tokens.count() == 2 && tokens[1] == "EMPTY")
|
|
|
|
{
|
|
|
|
invalidateTiles(-1, 0, 0, INT_MAX, INT_MAX);
|
|
|
|
}
|
2015-07-21 06:53:53 -05:00
|
|
|
else if (tokens.count() != 6)
|
2015-05-29 00:39:21 -05:00
|
|
|
{
|
2015-05-28 10:39:05 -05:00
|
|
|
return;
|
2015-05-29 00:39:21 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-07-21 06:53:53 -05:00
|
|
|
int part, x, y, width, height;
|
|
|
|
if (getTokenInteger(tokens[1], "part", part) &&
|
|
|
|
getTokenInteger(tokens[2], "x", x) &&
|
|
|
|
getTokenInteger(tokens[3], "y", y) &&
|
|
|
|
getTokenInteger(tokens[4], "width", width) &&
|
|
|
|
getTokenInteger(tokens[5], "height", height))
|
|
|
|
{
|
|
|
|
invalidateTiles(part, x, y, width, height);
|
|
|
|
}
|
2015-05-29 00:39:21 -05:00
|
|
|
}
|
2015-05-28 10:39:05 -05:00
|
|
|
}
|
|
|
|
|
2015-06-24 15:05:49 -05:00
|
|
|
std::string TileCache::toplevelCacheDirName()
|
2015-03-12 18:34:42 -05:00
|
|
|
{
|
2015-05-29 00:49:49 -05:00
|
|
|
SHA1Engine digestEngine;
|
2015-03-12 18:34:42 -05:00
|
|
|
|
|
|
|
digestEngine.update(_docURL.c_str(), _docURL.size());
|
|
|
|
|
2015-06-04 09:07:49 -05:00
|
|
|
return (LOOLWSD::cache + "/" +
|
2015-05-29 00:49:49 -05:00
|
|
|
DigestEngine::digestToHex(digestEngine.digest()).insert(3, "/").insert(2, "/").insert(1, "/"));
|
2015-03-12 18:34:42 -05:00
|
|
|
}
|
|
|
|
|
2015-06-24 15:05:49 -05:00
|
|
|
std::string TileCache::cacheDirName(bool useEditingCache)
|
|
|
|
{
|
|
|
|
if (useEditingCache)
|
|
|
|
return toplevelCacheDirName() + "/editing";
|
|
|
|
else
|
|
|
|
return toplevelCacheDirName() + "/persistent";
|
|
|
|
}
|
|
|
|
|
2015-04-27 13:24:05 -05:00
|
|
|
std::string TileCache::cacheFileName(int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, int tileHeight)
|
2015-03-12 18:34:42 -05:00
|
|
|
{
|
2015-04-27 13:24:05 -05:00
|
|
|
return (std::to_string(part) + "_" +
|
|
|
|
std::to_string(width) + "x" + std::to_string(height) + "." +
|
2015-03-12 18:34:42 -05:00
|
|
|
std::to_string(tilePosX) + "," + std::to_string(tilePosY) + "." +
|
|
|
|
std::to_string(tileWidth) + "x" + std::to_string(tileHeight) + ".png");
|
|
|
|
}
|
|
|
|
|
2015-05-28 10:39:05 -05:00
|
|
|
bool TileCache::parseCacheFileName(std::string& fileName, int& part, int& width, int& height, int& tilePosX, int& tilePosY, int& tileWidth, int& tileHeight)
|
|
|
|
{
|
2015-06-24 15:05:49 -05:00
|
|
|
return (std::sscanf(fileName.c_str(), "%d_%dx%d.%d,%d.%dx%d.png", &part, &width, &height, &tilePosX, &tilePosY, &tileWidth, &tileHeight) == 7);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TileCache::intersectsTile(std::string& fileName, int part, int x, int y, int width, int height)
|
|
|
|
{
|
|
|
|
int tilePart, tilePixelWidth, tilePixelHeight, tilePosX, tilePosY, tileWidth, tileHeight;
|
|
|
|
|
|
|
|
if (parseCacheFileName(fileName, tilePart, tilePixelWidth, tilePixelHeight, tilePosX, tilePosY, tileWidth, tileHeight))
|
|
|
|
{
|
|
|
|
if (part != -1 && tilePart != part)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
int left = std::max(x, tilePosX);
|
|
|
|
int right = std::min(x + width, tilePosX + tileWidth);
|
|
|
|
int top = std::max(y, tilePosY);
|
|
|
|
int bottom = std::min(y + height, tilePosY + tileHeight);
|
|
|
|
|
|
|
|
if (left <= right && top <= bottom)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2015-05-28 10:39:05 -05:00
|
|
|
}
|
|
|
|
|
2015-05-29 00:49:49 -05:00
|
|
|
Timestamp TileCache::getLastModified()
|
2015-03-12 18:34:42 -05:00
|
|
|
{
|
2015-06-24 15:05:49 -05:00
|
|
|
std::fstream modTimeFile(toplevelCacheDirName() + "/modtime.txt", std::ios::in);
|
2015-03-12 18:34:42 -05:00
|
|
|
|
|
|
|
if (!modTimeFile.is_open())
|
|
|
|
return 0;
|
|
|
|
|
2015-05-29 00:49:49 -05:00
|
|
|
Timestamp::TimeVal result;
|
2015-03-12 18:34:42 -05:00
|
|
|
modTimeFile >> result;
|
|
|
|
|
|
|
|
modTimeFile.close();
|
|
|
|
return result;
|
2015-03-12 09:18:35 -05:00
|
|
|
}
|
|
|
|
|
2015-08-04 13:37:05 -05:00
|
|
|
void TileCache::saveLastModified(const Poco::Timestamp& timestamp)
|
|
|
|
{
|
|
|
|
std::fstream modTimeFile(toplevelCacheDirName() + "/modtime.txt", std::ios::out);
|
|
|
|
modTimeFile << timestamp.raw() << std::endl;
|
|
|
|
modTimeFile.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TileCache::setup(const std::string& timestamp)
|
2015-05-29 04:23:57 -05:00
|
|
|
{
|
2015-08-04 13:37:05 -05:00
|
|
|
bool cleanEverything = true;
|
|
|
|
std::string filePath;
|
|
|
|
Timestamp lastModified;
|
|
|
|
|
|
|
|
try
|
2015-05-29 04:23:57 -05:00
|
|
|
{
|
2015-08-04 13:37:05 -05:00
|
|
|
URI uri(_docURL);
|
|
|
|
if (uri.getScheme() == "" ||
|
|
|
|
uri.getScheme() == "file")
|
2015-05-29 04:23:57 -05:00
|
|
|
{
|
2015-08-04 13:37:05 -05:00
|
|
|
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;
|
|
|
|
Application::instance().logger().information(Util::logPrefix() + "Timestamp provided externally: " + timestamp);
|
|
|
|
|
|
|
|
cleanEverything = (getLastModified() < Timestamp(lastModified));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// when no timestamp, and non-file, assume 'now'
|
|
|
|
lastModified = Timestamp();
|
|
|
|
}
|
|
|
|
|
|
|
|
File cacheDir(toplevelCacheDirName());
|
|
|
|
if (cacheDir.exists())
|
|
|
|
{
|
|
|
|
if (cleanEverything)
|
|
|
|
{
|
|
|
|
// document changed externally, clean up everything
|
|
|
|
cacheDir.remove(true);
|
|
|
|
Application::instance().logger().information(Util::logPrefix() + "Completely cleared cache: " + toplevelCacheDirName());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// remove only the Editing cache
|
|
|
|
File editingCacheDir(cacheDirName(true));
|
|
|
|
if (editingCacheDir.exists())
|
2015-06-24 15:05:49 -05:00
|
|
|
{
|
2015-08-04 13:37:05 -05:00
|
|
|
editingCacheDir.remove(true);
|
|
|
|
Application::instance().logger().information(Util::logPrefix() + "Cleared the editing cache: " + cacheDirName(true));
|
2015-06-24 15:05:49 -05:00
|
|
|
}
|
2015-05-29 04:23:57 -05:00
|
|
|
}
|
|
|
|
}
|
2015-08-04 13:37:05 -05:00
|
|
|
|
|
|
|
cacheDir.createDirectories();
|
|
|
|
|
|
|
|
saveLastModified(lastModified);
|
2015-05-29 04:23:57 -05:00
|
|
|
}
|
2015-03-12 18:34:42 -05:00
|
|
|
|
2015-03-12 09:18:35 -05:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|