Commit ecfd923b authored by Shashwat Jolly's avatar Shashwat Jolly

Switch to etebase_fs_cache API from local implementation

- Move caching functions to ClientState from Adapter. This was needed to hold to etebase_fs_cache object for the resource duration.
- Pass ClientState to journalsfetchjob and entriesfetchjob - makes accessing account and caching functions easy
- Switch out local caching functions to client state functions in etesyncresource.cpp
- Use username_agentId as etebase cache folders to prevent conflict between different resource instances with the same username
parent 851c28c5
Pipeline #36943 failed with stage
in 47 minutes and 34 seconds
......@@ -21,12 +21,11 @@
using namespace Akonadi;
using namespace EteSyncAPI;
EntriesFetchJob::EntriesFetchJob(const EtebaseAccount *account, const Akonadi::Collection &collection, EtebaseCollectionPtr etesyncCollection, const QString &cacheDir, QObject *parent)
EntriesFetchJob::EntriesFetchJob(const EteSyncClientState *clientState, const Akonadi::Collection &collection, EtebaseCollectionPtr etesyncCollection, QObject *parent)
: KJob(parent)
, mAccount(account)
, mClientState(clientState)
, mCollection(collection)
, mEtesyncCollection(std::move(etesyncCollection))
, mCacheDir(cacheDir)
{
}
......@@ -43,7 +42,15 @@ void EntriesFetchJob::start()
void EntriesFetchJob::fetchEntries()
{
if (!mAccount) {
if (!mClientState) {
setError(UserDefinedError);
setErrorText(QStringLiteral("EntriesFetchJob: EteSync client state is null"));
return;
}
EtebaseAccount *account = mClientState->account();
if (!account) {
setError(UserDefinedError);
setErrorText(QStringLiteral("EntriesFetchJob: Etebase account is null"));
return;
......@@ -61,7 +68,7 @@ void EntriesFetchJob::fetchEntries()
QString sToken = mCollection.remoteRevision();
bool done = 0;
EtebaseCollectionManagerPtr collectionManager(etebase_account_get_collection_manager(mAccount));
EtebaseCollectionManagerPtr collectionManager(etebase_account_get_collection_manager(account));
EtebaseItemManagerPtr itemManager(etebase_collection_manager_get_item_manager(collectionManager.get(), mEtesyncCollection.get()));
while (!done) {
......@@ -95,7 +102,7 @@ void EntriesFetchJob::fetchEntries()
Item item;
for (uintptr_t i = 0; i < dataLength; i++) {
saveEtebaseItemCache(itemManager.get(), etesyncItems[i], mCacheDir);
mClientState->saveEtebaseItemCache(etesyncItems[i], mEtesyncCollection.get());
setupItem(item, etesyncItems[i], type);
}
}
......
......@@ -12,6 +12,7 @@
#include <KJob>
#include "etebaseadapter.h"
#include "etesyncclientstate.h"
namespace EteSyncAPI {
class EntriesFetchJob : public KJob
......@@ -19,7 +20,7 @@ class EntriesFetchJob : public KJob
Q_OBJECT
public:
explicit EntriesFetchJob(const EtebaseAccount *account, const Akonadi::Collection &collection, EtebaseCollectionPtr etesyncCollection, const QString &cacheDir, QObject *parent = nullptr);
explicit EntriesFetchJob(const EteSyncClientState *mClientState, const Akonadi::Collection &collection, EtebaseCollectionPtr etesyncCollection, QObject *parent = nullptr);
void start() override;
......@@ -43,12 +44,11 @@ protected:
void setupItem(Akonadi::Item &item, const EtebaseItem *etesyncItem, const QString &type);
private:
const EtebaseAccount *mAccount = nullptr;
const EteSyncClientState *mClientState = nullptr;
Akonadi::Collection mCollection;
const EtebaseCollectionPtr mEtesyncCollection;
Akonadi::Item::List mItems;
Akonadi::Item::List mRemovedItems;
QString mCacheDir;
};
} // namespace EteSyncAPI
......
......@@ -4,8 +4,6 @@
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include <QFile>
#include "etebaseadapter.h"
#include "etesync_debug.h"
......@@ -19,209 +17,62 @@ QString QStringFromCharPtr(const CharPtr &str)
return ret;
}
void saveEtebaseAccountCache(EtebaseAccount *account, const QString &username, const QByteArray &encryptionKey, const QString &cacheDir)
{
if (!account) {
qCDebug(ETESYNC_LOG) << "Unable to save etebase account cache - account is null";
return;
}
qCDebug(ETESYNC_LOG) << "Saving cache for account" << username;
CharPtr cacheData(etebase_account_save(account, encryptionKey.constData(), encryptionKey.size()));
QString filePath = cacheDir + QStringLiteral("/") + username;
QFile file(filePath);
if (!file.open(QIODevice::WriteOnly)) {
qCDebug(ETESYNC_LOG) << "Unable to open " << filePath << file.errorString();
return;
}
file.write(QByteArray(cacheData.get()));
}
void saveEtebaseCollectionCache(const EtebaseCollectionManager *collectionManager, const EtebaseCollection *etesyncCollection, const QString &cacheDir)
EtebaseClientPtr etebase_client_new(const QString &client_name, const QString &server_url)
{
if (!etesyncCollection) {
qCDebug(ETESYNC_LOG) << "Unable to save collection cache - etesyncCollection is null";
return;
}
QString etesyncCollectionUid = QString::fromUtf8(etebase_collection_get_uid(etesyncCollection));
qCDebug(ETESYNC_LOG) << "Saving cache for collection" << etesyncCollectionUid;
uintptr_t ret_size;
EtebaseCachePtr cache(etebase_collection_manager_cache_save(collectionManager, etesyncCollection, &ret_size));
QByteArray cacheData((char *)cache.get(), ret_size);
QString filePath = cacheDir + QStringLiteral("/") + etesyncCollectionUid;
QFile file(filePath);
if (!file.open(QIODevice::WriteOnly)) {
qCDebug(ETESYNC_LOG) << "Unable to open " << filePath << file.errorString();
return;
}
file.write(cacheData);
return EtebaseClientPtr(etebase_client_new(charArrFromQString(client_name), charArrFromQString(server_url)));
}
void saveEtebaseItemCache(const EtebaseItemManager *itemManager, const EtebaseItem *etesyncItem, const QString &cacheDir)
EtebaseAccountPtr etebase_account_login(const EtebaseClient *client, const QString &username, const QString &password)
{
if (!etesyncItem) {
qCDebug(ETESYNC_LOG) << "Unable to save item cache - etesyncItem is null";
return;
}
QString etesyncItemUid = QString::fromUtf8(etebase_item_get_uid(etesyncItem));
qCDebug(ETESYNC_LOG) << "Saving cache for item" << etesyncItemUid;
uintptr_t ret_size;
EtebaseCachePtr cache(etebase_item_manager_cache_save(itemManager, etesyncItem, &ret_size));
QByteArray cacheData((char *)cache.get(), ret_size);
const QString filePath = cacheDir + QStringLiteral("/") + etesyncItemUid;
QFile file(filePath);
if (!file.open(QIODevice::WriteOnly)) {
qCDebug(ETESYNC_LOG) << "Unable to open " << filePath << file.errorString();
return;
}
file.write(cacheData);
return EtebaseAccountPtr(etebase_account_login(client, charArrFromQString(username), charArrFromQString(password)));
}
EtebaseAccountPtr getEtebaseAccountFromCache(const EtebaseClient *client, const QString &username, const QByteArray &encryptionKey, const QString &cacheDir)
void etebase_fetch_options_set_stoken(EtebaseFetchOptions *fetch_options, const QString &stoken)
{
if (!client) {
qCDebug(ETESYNC_LOG) << "Unable to get account from cache - client is null";
return nullptr;
}
QString accountCachePath = cacheDir + QStringLiteral("/") + username;
qCDebug(ETESYNC_LOG) << "accountCachePath" << accountCachePath;
QFile accountCacheFile(accountCachePath);
if (!accountCacheFile.exists()) {
qCDebug(ETESYNC_LOG) << "No cache file for account" << username;
return nullptr;
}
if (!accountCacheFile.open(QIODevice::ReadOnly)) {
qCDebug(ETESYNC_LOG) << "Unable to open " << accountCachePath << accountCacheFile.errorString();
return nullptr;
}
QByteArray accountCache = accountCacheFile.readAll();
EtebaseAccountPtr etebaseAccount(etebase_account_restore(client, accountCache.constData(), encryptionKey.constData(), encryptionKey.size()));
return etebaseAccount;
etebase_fetch_options_set_stoken(fetch_options, charArrFromQString(stoken));
}
EtebaseCollectionPtr getEtebaseCollectionFromCache(const EtebaseCollectionManager *collectionManager, const QString &collectionUid, const QString &cacheDir)
EtebaseCollectionMetadataPtr etebase_collection_metadata_new(const QString &type, const QString &name)
{
if (collectionUid.isEmpty()) {
qCDebug(ETESYNC_LOG) << "Unable to get collection cache - uid is empty";
return nullptr;
}
qCDebug(ETESYNC_LOG) << "Getting cache for collection" << collectionUid;
QString collectionCachePath = cacheDir + QLatin1Char('/') + collectionUid;
QFile collectionCacheFile(collectionCachePath);
if (!collectionCacheFile.exists()) {
qCDebug(ETESYNC_LOG) << "No cache file for collection" << collectionUid;
return nullptr;
}
if (!collectionCacheFile.open(QIODevice::ReadOnly)) {
qCDebug(ETESYNC_LOG) << "Unable to open " << collectionCachePath << collectionCacheFile.errorString();
return nullptr;
}
QByteArray collectionCache = collectionCacheFile.readAll();
if (collectionCache.isEmpty()) {
qCDebug(ETESYNC_LOG) << "Empty cache file for collection" << collectionUid;
return nullptr;
}
EtebaseCollectionPtr etesyncCollection(etebase_collection_manager_cache_load(collectionManager, collectionCache.constData(), collectionCache.size()));
return etesyncCollection;
return EtebaseCollectionMetadataPtr(etebase_collection_metadata_new(charArrFromQString(type), charArrFromQString(name)));
}
EtebaseItemPtr getEtebaseItemFromCache(const EtebaseItemManager *itemManager, const QString &itemUid, const QString &cacheDir)
void etebase_collection_metadata_set_color(EtebaseCollectionMetadata *meta_data, const QString &color)
{
if (itemUid.isEmpty()) {
qCDebug(ETESYNC_LOG) << "Unable to get item cache - uid is empty";
return nullptr;
}
qCDebug(ETESYNC_LOG) << "Getting cache for item" << itemUid;
QString itemCachePath = cacheDir + QLatin1Char('/') + itemUid;
QFile itemCacheFile(itemCachePath);
if (!itemCacheFile.exists()) {
qCDebug(ETESYNC_LOG) << "No cache file for item" << itemUid;
return nullptr;
}
if (!itemCacheFile.open(QIODevice::ReadOnly)) {
qCDebug(ETESYNC_LOG) << "Unable to open " << itemCachePath << itemCacheFile.errorString();
return nullptr;
}
QByteArray itemCache = itemCacheFile.readAll();
if (itemCache.isEmpty()) {
qCDebug(ETESYNC_LOG) << "Empty cache file for item" << itemUid;
return nullptr;
}
EtebaseItemPtr etesyncItem(etebase_item_manager_cache_load(itemManager, itemCache.constData(), itemCache.size()));
return etesyncItem;
etebase_collection_metadata_set_color(meta_data, charArrFromQString(color));
}
void deleteCacheFile(const QString &etebaseUid, const QString &cacheDir)
void etebase_collection_metadata_set_name(EtebaseCollectionMetadata *meta_data, const QString &name)
{
qCDebug(ETESYNC_LOG) << "Deleting cache file" << etebaseUid;
const QString path = cacheDir + QLatin1Char('/') + etebaseUid;
QFile file(path);
if (!file.remove()) {
qCDebug(ETESYNC_LOG) << "Unable to remove " << path << file.errorString();
return;
}
etebase_collection_metadata_set_name(meta_data, charArrFromQString(name));
}
EtebaseClientPtr etebase_client_new(const QString &client_name, const QString &server_url)
EtebaseFileSystemCachePtr etebase_fs_cache_new(const QString &path, const QString &username)
{
return EtebaseClientPtr(etebase_client_new(charArrFromQString(client_name), charArrFromQString(server_url)));
return EtebaseFileSystemCachePtr(etebase_fs_cache_new(charArrFromQString(path), charArrFromQString(username)));
}
EtebaseAccountPtr etebase_account_login(const EtebaseClient *client, const QString &username, const QString &password)
int32_t etebase_fs_cache_item_set(const EtebaseFileSystemCache *file_cache, const EtebaseItemManager *item_mgr, const QString &col_uid, const EtebaseItem *item)
{
return EtebaseAccountPtr(etebase_account_login(client, charArrFromQString(username), charArrFromQString(password)));
return etebase_fs_cache_item_set(file_cache, item_mgr, charArrFromQString(col_uid), item);
}
void etebase_fetch_options_set_stoken(EtebaseFetchOptions *fetch_options, const QString &stoken)
EtebaseCollectionPtr etebase_fs_cache_collection_get(const EtebaseFileSystemCache *fs_cache, const EtebaseCollectionManager *col_mgr, const QString &col_uid)
{
etebase_fetch_options_set_stoken(fetch_options, charArrFromQString(stoken));
return EtebaseCollectionPtr(etebase_fs_cache_collection_get(fs_cache, col_mgr, charArrFromQString(col_uid)));
}
EtebaseCollectionMetadataPtr etebase_collection_metadata_new(const QString &type, const QString &name)
EtebaseItemPtr etebase_fs_cache_item_get(const EtebaseFileSystemCache *fs_cache, const EtebaseItemManager *item_mgr, const QString &col_uid, const QString &item_uid)
{
return EtebaseCollectionMetadataPtr(etebase_collection_metadata_new(charArrFromQString(type), charArrFromQString(name)));
return EtebaseItemPtr(etebase_fs_cache_item_get(fs_cache, item_mgr, charArrFromQString(col_uid), charArrFromQString(item_uid)));
}
void etebase_collection_metadata_set_color(EtebaseCollectionMetadata *meta_data, const QString &color)
int32_t etebase_fs_cache_collection_unset(const EtebaseFileSystemCache *fs_cache, const EtebaseCollectionManager *col_mgr, const QString &col_uid)
{
etebase_collection_metadata_set_color(meta_data, charArrFromQString(color));
return etebase_fs_cache_collection_unset(fs_cache, col_mgr, charArrFromQString(col_uid));
}
void etebase_collection_metadata_set_name(EtebaseCollectionMetadata *meta_data, const QString &name)
int32_t etebase_fs_cache_item_unset(const EtebaseFileSystemCache *fs_cache, const EtebaseItemManager *item_mgr, const QString &col_uid, const QString &item_uid)
{
etebase_collection_metadata_set_name(meta_data, charArrFromQString(name));
return etebase_fs_cache_item_unset(fs_cache, item_mgr, charArrFromQString(col_uid), charArrFromQString(item_uid));
}
......@@ -42,6 +42,11 @@ struct EtebaseDeleter
etebase_collection_list_response_destroy(ptr);
}
void operator()(EtebaseCollectionManager *ptr)
{
etebase_collection_manager_destroy(ptr);
}
void operator()(EtebaseCollection *ptr)
{
etebase_collection_destroy(ptr);
......@@ -72,11 +77,13 @@ struct EtebaseDeleter
etebase_item_destroy(ptr);
}
void operator()(char *ptr)
void operator()(EtebaseFileSystemCache *ptr)
{
std::free(ptr);
etebase_fs_cache_destroy(ptr);
}
};
struct VoidDeleter {
void operator()(void *ptr)
{
std::free(ptr);
......@@ -94,17 +101,11 @@ using EtebaseItemManagerPtr = std::unique_ptr<EtebaseItemManager, EtebaseDeleter
using EtebaseItemListResponsePtr = std::unique_ptr<EtebaseItemListResponse, EtebaseDeleter>;
using EtebaseItemMetadataPtr = std::unique_ptr<EtebaseItemMetadata, EtebaseDeleter>;
using EtebaseItemPtr = std::unique_ptr<EtebaseItem, EtebaseDeleter>;
using EtebaseCachePtr = std::unique_ptr<void, EtebaseDeleter>;
using CharPtr = std::unique_ptr<char, EtebaseDeleter>;
using EtebaseFileSystemCachePtr = std::unique_ptr<EtebaseFileSystemCache, EtebaseDeleter>;
using EtebaseCachePtr = std::unique_ptr<void, VoidDeleter>;
using CharPtr = std::unique_ptr<char, VoidDeleter>;
QString QStringFromCharPtr(const CharPtr &str);
void saveEtebaseAccountCache(EtebaseAccount *account, const QString &username, const QByteArray &encryptionKey, const QString &cacheDir);
void saveEtebaseCollectionCache(const EtebaseCollectionManager *collectionManager, const EtebaseCollection *etesyncCollection, const QString &cacheDir);
void saveEtebaseItemCache(const EtebaseItemManager *itemManager, const EtebaseItem *etesyncItem, const QString &cacheDir);
EtebaseAccountPtr getEtebaseAccountFromCache(const EtebaseClient *client, const QString &username, const QByteArray &encryptionKey, const QString &cacheDir);
EtebaseCollectionPtr getEtebaseCollectionFromCache(const EtebaseCollectionManager *collectionManager, const QString &collectionUid, const QString &cacheDir);
EtebaseItemPtr getEtebaseItemFromCache(const EtebaseItemManager *itemManager, const QString &itemUid, const QString &cacheDir);
void deleteCacheFile(const QString &etebaseUid, const QString &cacheDir);
EtebaseClientPtr etebase_client_new(const QString &client_name, const QString &server_url);
......@@ -118,4 +119,16 @@ void etebase_collection_metadata_set_color(EtebaseCollectionMetadata *meta_data,
void etebase_collection_metadata_set_name(EtebaseCollectionMetadata *meta_data, const QString &name);
EtebaseFileSystemCachePtr etebase_fs_cache_new(const QString &path, const QString &username);
int32_t etebase_fs_cache_item_set(const EtebaseFileSystemCache *fs_cache, const EtebaseItemManager *item_mgr, const QString &col_uid, const EtebaseItem *item);
EtebaseCollectionPtr etebase_fs_cache_collection_get(const EtebaseFileSystemCache *fs_cache, const EtebaseCollectionManager *col_mgr, const QString &col_uid);
EtebaseItemPtr etebase_fs_cache_item_get(const EtebaseFileSystemCache *fs_cache, const EtebaseItemManager *item_mgr, const QString &col_uid, const QString &item_uid);
int32_t etebase_fs_cache_collection_unset(const EtebaseFileSystemCache *fs_cache, const EtebaseCollectionManager *col_mgr, const QString &col_uid);
int32_t etebase_fs_cache_item_unset(const EtebaseFileSystemCache *fs_cache, const EtebaseItemManager *item_mgr, const QString &col_uid, const QString &item_uid);
#endif
......@@ -14,7 +14,8 @@ using namespace KWallet;
static const QString etebaseWalletFolder = QStringLiteral("Akonadi Etebase");
EteSyncClientState::EteSyncClientState(WId winId) : mWinId(winId)
EteSyncClientState::EteSyncClientState(const QString &agentId, WId winId) : mAgentId(agentId)
, mWinId(winId)
{
}
......@@ -39,8 +40,11 @@ void EteSyncClientState::init()
return;
}
// Initialize etebase file cache
mEtebaseCache = etebase_fs_cache_new(Settings::self()->basePath(), mUsername + QStringLiteral("_") + mAgentId);
// Load Etebase account from cache
getAccount();
loadAccount();
Q_EMIT clientInitialised(true);
}
......@@ -84,6 +88,7 @@ bool EteSyncClientState::login(const QString &serverUrl, const QString &username
qCDebug(ETESYNC_LOG) << "Etebase error" << etebase_error_get_message();
return false;
}
mEtebaseCache = etebase_fs_cache_new(Settings::self()->basePath(), mUsername + QStringLiteral("_") + mAgentId);
return true;
}
......@@ -132,9 +137,6 @@ void EteSyncClientState::saveSettings()
Settings::self()->setBaseUrl(mServerUrl);
Settings::self()->setUsername(mUsername);
const QString cacheDir = Settings::self()->basePath() + QStringLiteral("/") + mUsername;
Settings::self()->setCacheDir(cacheDir);
Settings::self()->save();
}
......@@ -156,10 +158,13 @@ void EteSyncClientState::saveAccount()
qCDebug(ETESYNC_LOG) << "Wrote encryption key to wallet";
saveEtebaseAccountCache(mAccount.get(), mUsername, encryptionKey, Settings::self()->cacheDir());
if (etebase_fs_cache_save_account(mEtebaseCache.get(), mAccount.get(), encryptionKey.constData(), encryptionKey.size())) {
qCDebug(ETESYNC_LOG) << "Could not save account to cache";
qCDebug(ETESYNC_LOG) << "Etebase error:" << etebase_error_get_code() << etebase_error_get_message();
}
}
void EteSyncClientState::getAccount()
void EteSyncClientState::loadAccount()
{
if (!mWallet) {
qCDebug(ETESYNC_LOG) << "Get account - wallet not opened";
......@@ -181,7 +186,11 @@ void EteSyncClientState::getAccount()
qCDebug(ETESYNC_LOG) << "Read encryption key from wallet";
mAccount = getEtebaseAccountFromCache(mClient.get(), mUsername, encryptionKey, Settings::self()->cacheDir());
mAccount = EtebaseAccountPtr(etebase_fs_cache_load_account(mEtebaseCache.get(), mClient.get(), encryptionKey.constData(), encryptionKey.size()));
if (!mAccount) {
qCDebug(ETESYNC_LOG) << "Could not get etebase account from caache";
}
}
void EteSyncClientState::deleteWalletEntry()
......@@ -201,3 +210,127 @@ void EteSyncClientState::deleteWalletEntry()
qCDebug(ETESYNC_LOG) << "Deleted wallet entry";
}
void EteSyncClientState::saveEtebaseCollectionCache(const EtebaseCollection *etesyncCollection) const
{
if (!mAccount) {
qCDebug(ETESYNC_LOG) << "Unable to save collection cache - account is null";
return;
}
if (!etesyncCollection) {
qCDebug(ETESYNC_LOG) << "Unable to save collection cache - etesyncCollection is null";
return;
}
EtebaseCollectionManagerPtr collectionManager(etebase_account_get_collection_manager(mAccount.get()));
if (etebase_fs_cache_collection_set(mEtebaseCache.get(), collectionManager.get(), etesyncCollection)) {
qCDebug(ETESYNC_LOG) << "Could not save etebase collection cache for collection" << etebase_collection_get_uid(etesyncCollection);
return;
}
qCDebug(ETESYNC_LOG) << "Saved cache for collection" << etebase_collection_get_uid(etesyncCollection);
}
void EteSyncClientState::saveEtebaseItemCache(const EtebaseItem *etesyncItem, const EtebaseCollection *parentCollection) const
{
if (!mAccount) {
qCDebug(ETESYNC_LOG) << "Unable to save collection cache - account is null";
return;
}
if (!etesyncItem) {
qCDebug(ETESYNC_LOG) << "Unable to save item cache - etesyncItem is null";
return;
}
EtebaseCollectionManagerPtr collectionManager(etebase_account_get_collection_manager(mAccount.get()));
EtebaseItemManagerPtr itemManager(etebase_collection_manager_get_item_manager(collectionManager.get(), parentCollection));
QString collectionUid = QString::fromUtf8(etebase_collection_get_uid(parentCollection));
if (etebase_fs_cache_item_set(mEtebaseCache.get(), itemManager.get(), collectionUid, etesyncItem)) {
qCDebug(ETESYNC_LOG) << "Could not save etebase item cache for item" << etebase_item_get_uid(etesyncItem);
return;
}
qCDebug(ETESYNC_LOG) << "Saved cache for item" << etebase_item_get_uid(etesyncItem);
}
EtebaseCollectionPtr EteSyncClientState::getEtebaseCollectionFromCache(const QString &collectionUid) const
{
if (!mAccount) {
qCDebug(ETESYNC_LOG) << "Unable to get collection cache - account is null";
return nullptr;
}
if (collectionUid.isEmpty()) {
qCDebug(ETESYNC_LOG) << "Unable to get collection cache - uid is empty";
return nullptr;
}
qCDebug(ETESYNC_LOG) << "Getting cache for collection" << collectionUid;
EtebaseCollectionManagerPtr collectionManager(etebase_account_get_collection_manager(mAccount.get()));
return etebase_fs_cache_collection_get(mEtebaseCache.get(), collectionManager.get(), collectionUid);
}
EtebaseItemPtr EteSyncClientState::getEtebaseItemFromCache(const QString &itemUid, const EtebaseCollection *parentCollection) const
{
if (!mAccount) {
qCDebug(ETESYNC_LOG) << "Unable to get item cache - account is null";
return nullptr;
}
if (!parentCollection) {
qCDebug(ETESYNC_LOG) << "Unable to get item cache - parentCollection is null";
return nullptr;
}
if (itemUid.isEmpty()) {
qCDebug(ETESYNC_LOG) << "Unable to get item cache - uid is empty";
return nullptr;
}
qCDebug(ETESYNC_LOG) << "Getting cache for item" << itemUid;
EtebaseCollectionManagerPtr collectionManager(etebase_account_get_collection_manager(mAccount.get()));
EtebaseItemManagerPtr itemManager(etebase_collection_manager_get_item_manager(collectionManager.get(), parentCollection));
QString collectionUid = QString::fromUtf8(etebase_collection_get_uid(parentCollection));
return etebase_fs_cache_item_get(mEtebaseCache.get(), itemManager.get(), collectionUid, itemUid);
}
void EteSyncClientState::deleteEtebaseCollectionCache(const QString &collectionUid)
{
EtebaseCollectionManagerPtr collectionManager(etebase_account_get_collection_manager(mAccount.get()));
if (etebase_fs_cache_collection_unset(mEtebaseCache.get(), collectionManager.get(), collectionUid)) {
qCDebug(ETESYNC_LOG) << "Could not delete cache for collection" << collectionUid;
qCDebug(ETESYNC_LOG) << "Etebase error:" << etebase_error_get_code() << etebase_error_get_message();
return;
}
qCDebug(ETESYNC_LOG) << "Deleted cache for collection" << collectionUid;
}
void EteSyncClientState::deleteEtebaseItemCache(const QString &itemUid, const EtebaseCollection *parentCollection)
{
EtebaseCollectionManagerPtr collectionManager(etebase_account_get_collection_manager(mAccount.get()));
EtebaseItemManagerPtr itemManager(etebase_collection_manager_get_item_manager(collectionManager.get(), parentCollection));
const QString collectionUid = QString::fromUtf8(etebase_collection_get_uid(parentCollection));
if (etebase_fs_cache_item_unset(mEtebaseCache.get(), itemManager.get(), collectionUid, itemUid)) {
qCDebug(ETESYNC_LOG) << "Could not delete cache for item" << itemUid;
qCDebug(ETESYNC_LOG) << "Etebase error:" << etebase_error_get_code() << etebase_error_get_message();
return;
}
qCDebug(ETESYNC_LOG) << "Deleted cache for item" << itemUid;
}
void EteSyncClientState::deleteEtebaseUserCache()
{
if (etebase_fs_cache_clear_user(mEtebaseCache.get())) {
qCDebug(ETESYNC_LOG) << "Could not remove cache for user";
}
}
......@@ -18,7 +18,7 @@ class EteSyncClientState : public QObject
Q_OBJECT