2013-10-03 17:27:29 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SYNCJOURNALDB_H
|
|
|
|
#define SYNCJOURNALDB_H
|
|
|
|
|
|
|
|
#include <QObject>
|
2013-10-04 23:02:23 +04:00
|
|
|
#include <qmutex.h>
|
2013-10-16 13:59:54 +04:00
|
|
|
#include <QDateTime>
|
2013-11-11 14:11:45 +04:00
|
|
|
#include <QHash>
|
2013-10-03 17:27:29 +04:00
|
|
|
|
2014-04-25 01:45:20 +04:00
|
|
|
#include "utility.h"
|
2014-10-14 13:14:57 +04:00
|
|
|
#include "ownsql.h"
|
2014-04-25 01:45:20 +04:00
|
|
|
|
2013-10-03 17:27:29 +04:00
|
|
|
namespace Mirall {
|
|
|
|
class SyncJournalFileRecord;
|
2013-11-20 16:44:01 +04:00
|
|
|
class SyncJournalBlacklistRecord;
|
2013-10-03 17:27:29 +04:00
|
|
|
|
2014-04-01 15:41:47 +04:00
|
|
|
/**
|
|
|
|
* Class that handle the sync database
|
|
|
|
*
|
|
|
|
* This class is thread safe. All public function are locking the mutex.
|
|
|
|
*/
|
2014-04-25 01:45:20 +04:00
|
|
|
class OWNCLOUDSYNC_EXPORT SyncJournalDb : public QObject
|
2013-10-03 17:27:29 +04:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit SyncJournalDb(const QString& path, QObject *parent = 0);
|
2013-11-18 12:59:59 +04:00
|
|
|
virtual ~SyncJournalDb();
|
2013-10-03 17:27:29 +04:00
|
|
|
SyncJournalFileRecord getFileRecord( const QString& filename );
|
2013-10-03 19:48:04 +04:00
|
|
|
bool setFileRecord( const SyncJournalFileRecord& record );
|
2013-10-28 13:47:10 +04:00
|
|
|
bool deleteFileRecord( const QString& filename, bool recursively = false );
|
2013-10-04 16:44:57 +04:00
|
|
|
int getFileRecordCount();
|
|
|
|
bool exists();
|
2014-10-21 17:41:11 +04:00
|
|
|
void walCheckpoint();
|
2013-12-03 17:47:32 +04:00
|
|
|
|
2014-10-13 16:49:53 +04:00
|
|
|
QString databaseFilePath();
|
2014-10-13 16:14:43 +04:00
|
|
|
static qint64 getPHash(const QString& );
|
|
|
|
|
2013-11-20 16:44:01 +04:00
|
|
|
void updateBlacklistEntry( const SyncJournalBlacklistRecord& item );
|
|
|
|
void wipeBlacklistEntry(const QString& file);
|
2013-12-03 17:03:45 +04:00
|
|
|
int wipeBlacklist();
|
2013-12-03 17:47:32 +04:00
|
|
|
int blackListEntryCount();
|
2013-10-03 20:52:02 +04:00
|
|
|
|
2013-10-16 13:59:54 +04:00
|
|
|
struct DownloadInfo {
|
|
|
|
DownloadInfo() : _errorCount(0), _valid(false) {}
|
|
|
|
QString _tmpfile;
|
|
|
|
QByteArray _etag;
|
|
|
|
int _errorCount;
|
|
|
|
bool _valid;
|
|
|
|
};
|
|
|
|
struct UploadInfo {
|
2014-06-20 14:37:49 +04:00
|
|
|
UploadInfo() : _chunk(0), _transferid(0), _size(0), _errorCount(0), _valid(false) {}
|
2013-10-16 13:59:54 +04:00
|
|
|
int _chunk;
|
|
|
|
int _transferid;
|
|
|
|
quint64 _size; //currently unused
|
|
|
|
QDateTime _modtime;
|
|
|
|
int _errorCount;
|
|
|
|
bool _valid;
|
|
|
|
};
|
|
|
|
|
|
|
|
DownloadInfo getDownloadInfo(const QString &file);
|
|
|
|
void setDownloadInfo(const QString &file, const DownloadInfo &i);
|
2014-09-03 14:11:03 +04:00
|
|
|
QVector<DownloadInfo> getAndDeleteStaleDownloadInfos(const QSet<QString>& keep);
|
|
|
|
|
2013-10-16 13:59:54 +04:00
|
|
|
UploadInfo getUploadInfo(const QString &file);
|
|
|
|
void setUploadInfo(const QString &file, const UploadInfo &i);
|
2014-09-03 14:11:03 +04:00
|
|
|
bool deleteStaleUploadInfos(const QSet<QString>& keep);
|
|
|
|
|
2013-11-20 16:44:01 +04:00
|
|
|
SyncJournalBlacklistRecord blacklistEntry( const QString& );
|
2014-09-03 14:11:03 +04:00
|
|
|
bool deleteStaleBlacklistEntries(const QSet<QString>& keep);
|
|
|
|
|
2014-02-12 16:44:55 +04:00
|
|
|
void avoidRenamesOnNextSync(const QString &path);
|
2013-11-20 16:44:01 +04:00
|
|
|
|
2014-06-03 19:22:40 +04:00
|
|
|
/**
|
|
|
|
* Make sure that on the next sync, filName is not read from the DB but use the PROPFIND to
|
|
|
|
* get the info from the server
|
|
|
|
*/
|
|
|
|
void avoidReadFromDbOnNextSync(const QString& fileName);
|
|
|
|
|
2014-06-17 18:29:38 +04:00
|
|
|
bool postSyncCleanup( const QSet<QString>& items );
|
2013-10-16 13:59:54 +04:00
|
|
|
|
2013-11-18 12:59:59 +04:00
|
|
|
/* Because sqlite transactions is really slow, we encapsulate everything in big transactions
|
|
|
|
* Commit will actually commit the transaction and create a new one.
|
|
|
|
*/
|
2013-11-21 14:13:58 +04:00
|
|
|
void commit(const QString &context, bool startTrans = true);
|
2014-10-20 19:20:58 +04:00
|
|
|
void commitIfNeededAndStartNewTransaction(const QString &context);
|
2013-11-18 12:59:59 +04:00
|
|
|
|
2013-11-18 12:58:02 +04:00
|
|
|
void close();
|
2013-11-21 14:13:58 +04:00
|
|
|
|
2014-04-01 15:41:47 +04:00
|
|
|
/**
|
|
|
|
* return true if everything is correct
|
|
|
|
*/
|
|
|
|
bool isConnected();
|
|
|
|
|
2014-04-25 15:31:44 +04:00
|
|
|
/**
|
|
|
|
* Tell the sync engine if we need to disable the fetch from db to be sure that the fileid
|
|
|
|
* are updated.
|
|
|
|
*/
|
|
|
|
bool isUpdateFrom_1_5();
|
|
|
|
|
2013-10-03 17:27:29 +04:00
|
|
|
private:
|
2013-10-25 15:30:45 +04:00
|
|
|
bool updateDatabaseStructure();
|
2014-10-14 13:14:57 +04:00
|
|
|
bool sqlFail(const QString& log, const SqlQuery &query );
|
2013-11-25 18:11:37 +04:00
|
|
|
void commitInternal(const QString &context, bool startTrans = true);
|
|
|
|
void startTransaction();
|
|
|
|
void commitTransaction();
|
|
|
|
QStringList tableColumns( const QString& table );
|
2014-04-01 15:41:47 +04:00
|
|
|
bool checkConnect();
|
2013-10-25 15:30:45 +04:00
|
|
|
|
2014-10-14 13:14:57 +04:00
|
|
|
SqlDatabase _db;
|
2014-10-13 16:49:53 +04:00
|
|
|
QString _dbFile;
|
2013-10-04 23:02:23 +04:00
|
|
|
QMutex _mutex; // Public functions are protected with the mutex.
|
2013-11-21 14:13:58 +04:00
|
|
|
int _transaction;
|
2014-04-25 15:31:44 +04:00
|
|
|
bool _possibleUpgradeFromMirall_1_5;
|
2014-10-14 13:14:57 +04:00
|
|
|
QScopedPointer<SqlQuery> _getFileRecordQuery;
|
|
|
|
QScopedPointer<SqlQuery> _setFileRecordQuery;
|
|
|
|
QScopedPointer<SqlQuery> _getDownloadInfoQuery;
|
|
|
|
QScopedPointer<SqlQuery> _setDownloadInfoQuery;
|
|
|
|
QScopedPointer<SqlQuery> _deleteDownloadInfoQuery;
|
|
|
|
QScopedPointer<SqlQuery> _getUploadInfoQuery;
|
|
|
|
QScopedPointer<SqlQuery> _setUploadInfoQuery;
|
|
|
|
QScopedPointer<SqlQuery> _deleteUploadInfoQuery;
|
|
|
|
QScopedPointer<SqlQuery> _deleteFileRecordPhash;
|
|
|
|
QScopedPointer<SqlQuery> _deleteFileRecordRecursively;
|
|
|
|
QScopedPointer<SqlQuery> _blacklistQuery;
|
2014-08-07 14:10:32 +04:00
|
|
|
|
|
|
|
/* This is the list of paths we called avoidReadFromDbOnNextSync on.
|
|
|
|
* It means that they should not be written to the DB in any case since doing
|
|
|
|
* that would write the etag and would void the purpose of avoidReadFromDbOnNextSync
|
|
|
|
*/
|
|
|
|
QList<QString> _avoidReadFromDbOnNextSyncFilter;
|
2013-10-03 17:27:29 +04:00
|
|
|
};
|
|
|
|
|
2014-10-23 17:15:47 +04:00
|
|
|
bool operator==(const SyncJournalDb::DownloadInfo & lhs,
|
|
|
|
const SyncJournalDb::DownloadInfo & rhs);
|
|
|
|
bool operator==(const SyncJournalDb::UploadInfo & lhs,
|
|
|
|
const SyncJournalDb::UploadInfo & rhs);
|
|
|
|
|
2013-10-03 17:27:29 +04:00
|
|
|
} // namespace Mirall
|
|
|
|
#endif // SYNCJOURNALDB_H
|