/usr/include/owncloudsync/mirall/syncjournaldb.h is in libowncloudsync-dev 2.2.4+dfsg-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | /*
* 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>
#include <qmutex.h>
#include <QDateTime>
#include <QHash>
#include "utility.h"
#include "ownsql.h"
namespace OCC {
class SyncJournalFileRecord;
class SyncJournalErrorBlacklistRecord;
/**
* @brief Class that handles the sync database
*
* This class is thread safe. All public functions lock the mutex.
* @ingroup libsync
*/
class OWNCLOUDSYNC_EXPORT SyncJournalDb : public QObject
{
Q_OBJECT
public:
explicit SyncJournalDb(const QString& path, QObject *parent = 0);
virtual ~SyncJournalDb();
// to verify that the record could be queried successfully check
// with SyncJournalFileRecord::isValid()
SyncJournalFileRecord getFileRecord(const QString& filename);
bool setFileRecord( const SyncJournalFileRecord& record );
/// Like setFileRecord, but preserves checksums
bool setFileRecordMetadata( const SyncJournalFileRecord& record );
bool deleteFileRecord( const QString& filename, bool recursively = false );
int getFileRecordCount();
bool updateFileRecordChecksum(const QString& filename,
const QByteArray& contentChecksum,
const QByteArray& contentChecksumType);
bool exists();
void walCheckpoint();
QString databaseFilePath();
static qint64 getPHash(const QString& );
void updateErrorBlacklistEntry( const SyncJournalErrorBlacklistRecord& item );
void wipeErrorBlacklistEntry(const QString& file);
int wipeErrorBlacklist();
int errorBlackListEntryCount();
struct DownloadInfo {
DownloadInfo() : _errorCount(0), _valid(false) {}
QString _tmpfile;
QByteArray _etag;
int _errorCount;
bool _valid;
};
struct UploadInfo {
UploadInfo() : _chunk(0), _transferid(0), _size(0), _errorCount(0), _valid(false) {}
int _chunk;
int _transferid;
quint64 _size; //currently unused
QDateTime _modtime;
int _errorCount;
bool _valid;
};
struct PollInfo {
QString _file;
QString _url;
time_t _modtime;
};
DownloadInfo getDownloadInfo(const QString &file);
void setDownloadInfo(const QString &file, const DownloadInfo &i);
QVector<DownloadInfo> getAndDeleteStaleDownloadInfos(const QSet<QString>& keep);
int downloadInfoCount();
UploadInfo getUploadInfo(const QString &file);
void setUploadInfo(const QString &file, const UploadInfo &i);
bool deleteStaleUploadInfos(const QSet<QString>& keep);
SyncJournalErrorBlacklistRecord errorBlacklistEntry( const QString& );
bool deleteStaleErrorBlacklistEntries(const QSet<QString>& keep);
void avoidRenamesOnNextSync(const QString &path);
void setPollInfo(const PollInfo &);
QVector<PollInfo> getPollInfos();
enum SelectiveSyncListType {
/** The black list is the list of folders that are unselected in the selective sync dialog.
* For the sync engine, those folders are considered as if they were not there, so the local
* folders will be deleted */
SelectiveSyncBlackList = 1,
/** When a shared folder has a size bigger than a configured size, it is by default not sync'ed
* Unless it is in the white list, in which case the folder is sync'ed and all its children.
* If a folder is both on the black and the white list, the black list wins */
SelectiveSyncWhiteList = 2,
/** List of big sync folders that have not been confirmed by the user yet and that the UI
* should notify about */
SelectiveSyncUndecidedList = 3
};
/* return the specified list from the database */
QStringList getSelectiveSyncList(SelectiveSyncListType type, bool *ok);
/* Write the selective sync list (remove all other entries of that list */
void setSelectiveSyncList(SelectiveSyncListType type, const QStringList &list);
/**
* Make sure that on the next sync, fileName is not read from the DB but uses the PROPFIND to
* get the info from the server
*/
void avoidReadFromDbOnNextSync(const QString& fileName);
/**
* Ensures full remote discovery happens on the next sync.
*
* Equivalent to calling avoidReadFromDbOnNextSync() for all files.
*/
void forceRemoteDiscoveryNextSync();
bool postSyncCleanup(const QSet<QString>& filepathsToKeep,
const QSet<QString>& prefixesToKeep);
/* Because sqlite transactions are really slow, we encapsulate everything in big transactions
* Commit will actually commit the transaction and create a new one.
*/
void commit(const QString &context, bool startTrans = true);
void commitIfNeededAndStartNewTransaction(const QString &context);
void close();
/**
* return true if everything is correct
*/
bool isConnected();
/**
* Returns the checksum type for an id.
*/
QByteArray getChecksumType(int checksumTypeId);
private:
bool updateDatabaseStructure();
bool updateMetadataTableStructure();
bool updateErrorBlacklistTableStructure();
bool sqlFail(const QString& log, const SqlQuery &query );
void commitInternal(const QString &context, bool startTrans = true);
void startTransaction();
void commitTransaction();
QStringList tableColumns( const QString& table );
bool checkConnect();
// Same as forceRemoteDiscoveryNextSync but without acquiring the lock
void forceRemoteDiscoveryNextSyncLocked();
// Returns the integer id of the checksum type
//
// Returns 0 on failure and for empty checksum types.
int mapChecksumType(const QByteArray& checksumType);
SqlDatabase _db;
QString _dbFile;
QMutex _mutex; // Public functions are protected with the mutex.
int _transaction;
// NOTE! when adding a query, don't forget to reset it in SyncJournalDb::close
QScopedPointer<SqlQuery> _getFileRecordQuery;
QScopedPointer<SqlQuery> _setFileRecordQuery;
QScopedPointer<SqlQuery> _setFileRecordChecksumQuery;
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> _getErrorBlacklistQuery;
QScopedPointer<SqlQuery> _setErrorBlacklistQuery;
QScopedPointer<SqlQuery> _getSelectiveSyncListQuery;
QScopedPointer<SqlQuery> _getChecksumTypeIdQuery;
QScopedPointer<SqlQuery> _getChecksumTypeQuery;
QScopedPointer<SqlQuery> _insertChecksumTypeQuery;
/* 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;
};
bool OWNCLOUDSYNC_EXPORT
operator==(const SyncJournalDb::DownloadInfo & lhs,
const SyncJournalDb::DownloadInfo & rhs);
bool OWNCLOUDSYNC_EXPORT
operator==(const SyncJournalDb::UploadInfo & lhs,
const SyncJournalDb::UploadInfo & rhs);
} // namespace OCC
#endif // SYNCJOURNALDB_H
|