[Companion] Rework SD Sync implementation:
~ Move UI to new FileSyncDialog class; ~ Improve UI responsiveness during operation (closes #5005); + Add log verbosity option (also helps with UI response); + Add several filtering settings in new "extra options" panel (include/exlude patterns, symlinks, recursive, empty folders); ~ Exclude patterns ".*" and "System Volume*" by default (addresses #5213, #5106); + Sanity check file timestamps when using date comparison, future dates are invalid (addresses #5735); ~ Folders are no longer included in file counts (total/created/etc); ~ Ignore unreadable files/dirs (also enables NTFS permissions check); ~ Switch from QMutex to QReadWriteLock.
This commit is contained in:
@@ -18,13 +18,17 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef _PROCESS_SYNC_H_
|
||||
#define _PROCESS_SYNC_H_
|
||||
#ifndef PROCESS_SYNC_H
|
||||
#define PROCESS_SYNC_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QMutex>
|
||||
#include <QString>
|
||||
#include <QDirIterator>
|
||||
#include <QReadWriteLock>
|
||||
#include <QRegExp>
|
||||
#include <QVector>
|
||||
|
||||
class SyncProcess : public QObject
|
||||
{
|
||||
@@ -32,25 +36,75 @@ class SyncProcess : public QObject
|
||||
|
||||
public:
|
||||
enum SyncDirection {
|
||||
SYNC_A2B_B2A,
|
||||
SYNC_A2B_B2A = 0,
|
||||
SYNC_B2A_A2B,
|
||||
SYNC_A2B,
|
||||
SYNC_B2A
|
||||
};
|
||||
Q_ENUM(SyncDirection)
|
||||
|
||||
enum SyncCompareType {
|
||||
OVERWR_NEWER_IF_DIFF,
|
||||
OVERWR_NEWER_IF_DIFF = 0,
|
||||
OVERWR_NEWER_ALWAYS,
|
||||
OVERWR_IF_DIFF,
|
||||
OVERWR_ALWAYS
|
||||
};
|
||||
Q_ENUM(SyncCompareType)
|
||||
|
||||
SyncProcess(const QString & folderA,
|
||||
const QString & folderB,
|
||||
const int & syncDirection = SYNC_A2B_B2A,
|
||||
const int & compareType = OVERWR_NEWER_IF_DIFF,
|
||||
const qint64 & maxFileSize = 5*1024*1024,
|
||||
const bool dryRun = false);
|
||||
enum SyncOptionFlag {
|
||||
OPT_NONE = 0,
|
||||
OPT_DRY_RUN = 0x01,
|
||||
OPT_SKIP_EMPTY_DIR = 0x02,
|
||||
OPT_RECURSIVE = 0x04,
|
||||
OPT_SKIP_DIR_LINKS = 0x08
|
||||
};
|
||||
Q_DECLARE_FLAGS(SyncOptionFlags, SyncOptionFlag)
|
||||
Q_FLAG(SyncOptionFlags)
|
||||
|
||||
// TODO: perhaps move this to AppData/saved settings once that refactoring is merged.
|
||||
struct SyncOptions {
|
||||
explicit SyncOptions() { reset(); }
|
||||
|
||||
QString folderA;
|
||||
QString folderB;
|
||||
QString excludeFilter; // CSV list of glob pattern(s)
|
||||
QString includeFilter; // CSV list of glob pattern(s)
|
||||
qint64 maxFileSize; // Bytes
|
||||
int direction; // SyncDirection
|
||||
int compareType; // SyncCompareType
|
||||
int flags; // SyncOptionFlags
|
||||
int dirFilterFlags; // QDir::Filters
|
||||
int logLevel; // QtMsgType (see ProgressWidget::addMessage())
|
||||
|
||||
void reset()
|
||||
{
|
||||
excludeFilter = QStringLiteral(".*,System Volume*");
|
||||
includeFilter.clear();
|
||||
direction = SYNC_A2B_B2A;
|
||||
compareType = OVERWR_NEWER_IF_DIFF;
|
||||
maxFileSize = 2 * 1024 * 1024;
|
||||
logLevel = QtWarningMsg;
|
||||
flags = OPT_RECURSIVE;
|
||||
dirFilterFlags = QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot | QDir::Readable;
|
||||
}
|
||||
|
||||
friend inline QDebug operator<<(QDebug debug, const SyncOptions &o) {
|
||||
return debug << "Incl:" << o.includeFilter << "Excl:" << o.excludeFilter << SyncDirection(o.direction) << SyncCompareType(o.compareType) << SyncOptionFlags(o.flags) << QDir::Filters(o.dirFilterFlags);
|
||||
}
|
||||
};
|
||||
|
||||
struct SyncStatus {
|
||||
int index;
|
||||
int count;
|
||||
int created;
|
||||
int updated;
|
||||
int skipped;
|
||||
int errored;
|
||||
void clear() { memset(this, 0, sizeof(SyncStatus)); }
|
||||
};
|
||||
|
||||
explicit SyncProcess(const SyncOptions & options);
|
||||
~SyncProcess();
|
||||
|
||||
public slots:
|
||||
void run();
|
||||
@@ -60,34 +114,39 @@ class SyncProcess : public QObject
|
||||
void started();
|
||||
void finished();
|
||||
void fileCountChanged(int count);
|
||||
void progressStep(int step);
|
||||
void progressMessage(const QString & text, const int & type);
|
||||
void statusMessage(const QString & text);
|
||||
void statusUpdate(const SyncProcess::SyncStatus & status);
|
||||
void statusMessage(const QString & text, const int & type = QtInfoMsg);
|
||||
void progressMessage(const QString & text, const int & type = QtInfoMsg, bool richText = false);
|
||||
|
||||
protected:
|
||||
enum FileFilterResult { FILE_ALLOW, FILE_OVERSIZE, FILE_EXCLUDE, FILE_LINK_IGNORE };
|
||||
|
||||
bool isStopRequsted();
|
||||
void finish();
|
||||
FileFilterResult fileFilter(const QFileInfo & fileInfo);
|
||||
QFileInfoList dirInfoList(const QString & directory);
|
||||
int getFilesCount(const QString & directory);
|
||||
void updateDir(const QString & source, const QString & destination);
|
||||
void pushDirEntries(const QFileInfo & fi, QMutableListIterator<QFileInfo> &it);
|
||||
bool updateEntry(const QString & entry, const QDir & source, const QDir & destination);
|
||||
void pause();
|
||||
void emitProgressMessage(const QString &text, int type);
|
||||
|
||||
QString folder1;
|
||||
QString folder2;
|
||||
SyncDirection direction;
|
||||
SyncCompareType ctype;
|
||||
qint64 maxFileSize; // Bytes
|
||||
QDir::Filters dirFilters;
|
||||
QMutex stopReqMutex;
|
||||
QString reportTemplate;
|
||||
SyncOptions m_options;
|
||||
SyncStatus m_stat;
|
||||
QReadWriteLock stopReqMutex;
|
||||
QString testRunStr;
|
||||
int index;
|
||||
int count;
|
||||
int created;
|
||||
int updated;
|
||||
int skipped;
|
||||
int errored;
|
||||
bool dryRun;
|
||||
QVector<QRegExp> m_excludeFilters;
|
||||
QStringList m_dirIteratorFilters;
|
||||
QDir::Filters m_dirFilters;
|
||||
QDateTime m_startTime;
|
||||
unsigned long m_pauseTime;
|
||||
bool stopping;
|
||||
};
|
||||
|
||||
#endif // _PROCESS_SYNC_H_
|
||||
Q_DECLARE_METATYPE(SyncProcess::SyncOptions)
|
||||
Q_DECLARE_TYPEINFO(SyncProcess::SyncOptions, Q_MOVABLE_TYPE);
|
||||
Q_DECLARE_METATYPE(SyncProcess::SyncStatus)
|
||||
Q_DECLARE_TYPEINFO(SyncProcess::SyncStatus, Q_PRIMITIVE_TYPE);
|
||||
|
||||
#endif // PROCESS_SYNC_H
|
||||
|
||||
Reference in New Issue
Block a user