/usr/include/owncloudsync/mirall/syncengine.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 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | /*
* Copyright (C) by Duncan Mac-Vicar P. <duncan@kde.org>
* 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; either version 2 of the License, or
* (at your option) any later version.
*
* 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 CSYNCTHREAD_H
#define CSYNCTHREAD_H
#include <stdint.h>
#include <QMutex>
#include <QThread>
#include <QString>
#include <QSet>
#include <QMap>
#include <QStringList>
#include <QSharedPointer>
#include <csync.h>
// when do we go away with this private/public separation?
#include <csync_private.h>
#include "excludedfiles.h"
#include "syncfileitem.h"
#include "progressdispatcher.h"
#include "utility.h"
#include "syncfilestatustracker.h"
#include "accountfwd.h"
#include "discoveryphase.h"
#include "checksums.h"
class QProcess;
namespace OCC {
class SyncJournalFileRecord;
class SyncJournalDb;
class OwncloudPropagator;
class PropagatorJob;
/**
* @brief The SyncEngine class
* @ingroup libsync
*/
class OWNCLOUDSYNC_EXPORT SyncEngine : public QObject
{
Q_OBJECT
public:
SyncEngine(AccountPtr account, const QString &localPath,
const QUrl &remoteURL, const QString &remotePath, SyncJournalDb *journal);
~SyncEngine();
static QString csyncErrorToString( CSYNC_STATUS);
Q_INVOKABLE void startSync();
void setNetworkLimits(int upload, int download);
/* Abort the sync. Called from the main thread */
void abort();
bool isSyncRunning() const { return _syncRunning; }
/* Set the maximum size a folder can have without asking for confirmation
* -1 means infinite
*/
void setNewBigFolderSizeLimit(qint64 limit) { _newBigFolderSizeLimit = limit; }
bool ignoreHiddenFiles() const { return _csync_ctx->ignore_hidden_files; }
void setIgnoreHiddenFiles(bool ignore) { _csync_ctx->ignore_hidden_files = ignore; }
ExcludedFiles &excludedFiles() { return *_excludedFiles; }
Utility::StopWatch &stopWatch() { return _stopWatch; }
SyncFileStatusTracker &syncFileStatusTracker() { return *_syncFileStatusTracker; }
/* Return true if we detected that another sync is needed to complete the sync */
bool isAnotherSyncNeeded() { return _anotherSyncNeeded; }
SyncFileItem* findSyncItem(const QString &fileName) const;
/** Get the ms since a file was touched, or -1 if it wasn't.
*
* Thread-safe.
*/
qint64 timeSinceFileTouched(const QString& fn) const;
AccountPtr account() const;
SyncJournalDb *journal() const { return _journal; }
QString localPath() const { return _localPath; }
/**
* Minimum age, in milisecond, of a file that can be uploaded.
* Files more recent than that are not going to be uploaeded as they are considered
* too young and possibly still changing
*/
static qint64 minimumFileAgeForUpload; // in ms
signals:
void csyncError( const QString& );
void csyncUnavailable();
// During update, before reconcile
void rootEtag(QString);
void folderDiscovered(bool local, const QString &folderUrl);
// before actual syncing (after update+reconcile) for each item
void syncItemDiscovered(const SyncFileItem&);
// after the above signals. with the items that actually need propagating
void aboutToPropagate(SyncFileItemVector&);
// after each item completed by a job (successful or not)
void itemCompleted(const SyncFileItem&, const PropagatorJob&);
// after sync is done
void treeWalkResult(const SyncFileItemVector&);
void transmissionProgress( const ProgressInfo& progress );
void finished(bool success);
void started();
/**
* Emited when the sync engine detects that all the files have been removed or change.
* This usually happen when the server was reset or something.
* Set *cancel to true in a slot connected from this signal to abort the sync.
*/
void aboutToRemoveAllFiles(SyncFileItem::Direction direction, bool *cancel);
/**
* Emited when the sync engine detects that all the files are changed to dates in the past.
* This usually happen when a backup was restored on the server from an earlier date.
* Set *restore to true in a slot connected from this signal to re-upload all files.
*/
void aboutToRestoreBackup(bool *restore);
// A new folder was discovered and was not synced because of the confirmation feature
void newBigFolder(const QString &folder);
/** Emitted when propagation has problems with a locked file.
*
* Forwarded from OwncloudPropagator::seenLockedFile.
*/
void seenLockedFile(const QString &fileName);
private slots:
void slotRootEtagReceived(const QString &);
void slotItemCompleted(const SyncFileItem& item, const PropagatorJob & job);
void slotFinished();
void slotProgress(const SyncFileItem& item, quint64 curent);
void slotDiscoveryJobFinished(int updateResult);
void slotCleanPollsJobAborted(const QString &error);
private:
void handleSyncError(CSYNC *ctx, const char *state);
static int treewalkLocal( TREE_WALK_FILE*, void *);
static int treewalkRemote( TREE_WALK_FILE*, void *);
int treewalkFile( TREE_WALK_FILE*, bool );
bool checkErrorBlacklisting( SyncFileItem &item );
// Cleans up unnecessary downloadinfo entries in the journal as well
// as their temporary files.
void deleteStaleDownloadInfos();
// Removes stale uploadinfos from the journal.
void deleteStaleUploadInfos();
// Removes stale error blacklist entries from the journal.
void deleteStaleErrorBlacklistEntries();
// cleanup and emit the finished signal
void finalize(bool success);
static bool s_anySyncRunning; //true when one sync is running somewhere (for debugging)
// Must only be acessed during update and reconcile
QMap<QString, SyncFileItemPtr> _syncItemMap;
// should be called _syncItems (present tense). It's the items from the _syncItemMap but
// sorted and re-adjusted based on permissions.
SyncFileItemVector _syncedItems;
AccountPtr _account;
CSYNC *_csync_ctx;
bool _needsUpdate;
bool _syncRunning;
QString _localPath;
QUrl _remoteUrl;
QString _remotePath;
QString _remoteRootEtag;
SyncJournalDb *_journal;
QPointer<DiscoveryMainThread> _discoveryMainThread;
QSharedPointer <OwncloudPropagator> _propagator;
QString _lastDeleted; // if the last item was a path and it has been deleted
// After a sync, only the syncdb entries whose filenames appear in this
// set will be kept. See _temporarilyUnavailablePaths.
QSet<QString> _seenFiles;
// Some paths might be temporarily unavailable on the server, for
// example due to 503 Storage not available. Deleting information
// about the files from the database in these cases would lead to
// incorrect synchronization.
// Therefore all syncdb entries whose filename starts with one of
// the paths in this set will be kept.
// The specific case that fails otherwise is deleting a local file
// while the remote says storage not available.
QSet<QString> _temporarilyUnavailablePaths;
QThread _thread;
QScopedPointer<ProgressInfo> _progressInfo;
QScopedPointer<ExcludedFiles> _excludedFiles;
QScopedPointer<SyncFileStatusTracker> _syncFileStatusTracker;
Utility::StopWatch _stopWatch;
// maps the origin and the target of the folders that have been renamed
QHash<QString, QString> _renamedFolders;
QString adjustRenamedPath(const QString &original);
/**
* check if we are allowed to propagate everything, and if we are not, adjust the instructions
* to recover
*/
void checkForPermission();
QByteArray getPermissions(const QString& file) const;
/**
* Instead of downloading files from the server, upload the files to the server
*/
void restoreOldFiles();
bool _hasNoneFiles; // true if there is at least one file which was not changed on the server
bool _hasRemoveFile; // true if there is at leasr one file with instruction REMOVE
bool _hasForwardInTimeFiles; // true if there is at least one file from the server that goes forward in time
int _backInTimeFiles; // number of files which goes back in time from the server
int _uploadLimit;
int _downloadLimit;
/* maximum size a folder can have without asking for confirmation: -1 means infinite */
qint64 _newBigFolderSizeLimit;
// hash containing the permissions on the remote directory
QHash<QString, QByteArray> _remotePerms;
/// Hook for computing checksums from csync_update
CSyncChecksumHook _checksum_hook;
bool _anotherSyncNeeded;
};
}
#endif // CSYNCTHREAD_H
|