2013-09-16 00:49:24 +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
|
2016-10-25 12:00:07 +03:00
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2013-09-16 00:49:24 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2013-01-15 23:41:52 +04:00
|
|
|
#ifndef SYNCFILEITEM_H
|
|
|
|
#define SYNCFILEITEM_H
|
|
|
|
|
|
|
|
#include <QVector>
|
2013-05-03 21:11:00 +04:00
|
|
|
#include <QString>
|
2014-03-26 21:02:25 +04:00
|
|
|
#include <QDateTime>
|
2013-05-16 15:54:22 +04:00
|
|
|
#include <QMetaType>
|
2015-04-15 16:19:11 +03:00
|
|
|
#include <QSharedPointer>
|
2013-01-15 23:41:52 +04:00
|
|
|
|
|
|
|
#include <csync.h>
|
|
|
|
|
2018-10-20 14:25:22 +03:00
|
|
|
#include <owncloudlib.h>
|
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
namespace OCC {
|
2013-01-15 23:41:52 +04:00
|
|
|
|
2017-08-30 12:17:23 +03:00
|
|
|
class SyncFileItem;
|
|
|
|
class SyncJournalFileRecord;
|
2020-08-12 16:23:11 +03:00
|
|
|
using SyncFileItemPtr = QSharedPointer<SyncFileItem>;
|
2017-08-30 12:17:23 +03:00
|
|
|
|
2015-06-29 19:56:09 +03:00
|
|
|
/**
|
|
|
|
* @brief The SyncFileItem class
|
|
|
|
* @ingroup libsync
|
2015-06-26 18:07:47 +03:00
|
|
|
*/
|
2018-10-20 14:25:22 +03:00
|
|
|
class OWNCLOUDSYNC_EXPORT SyncFileItem
|
2013-01-15 23:41:52 +04:00
|
|
|
{
|
2018-07-10 11:21:45 +03:00
|
|
|
Q_GADGET
|
2013-01-15 23:41:52 +04:00
|
|
|
public:
|
2013-10-04 17:13:36 +04:00
|
|
|
enum Direction {
|
2013-08-07 14:15:28 +04:00
|
|
|
None = 0,
|
|
|
|
Up,
|
2013-10-04 17:13:36 +04:00
|
|
|
Down
|
|
|
|
};
|
2018-07-10 11:21:45 +03:00
|
|
|
Q_ENUM(Direction)
|
2013-08-07 14:15:28 +04:00
|
|
|
|
2017-06-27 15:17:26 +03:00
|
|
|
enum Status { // stored in 4 bits
|
2013-10-04 17:13:36 +04:00
|
|
|
NoStatus,
|
|
|
|
|
|
|
|
FatalError, ///< Error that causes the sync to stop
|
|
|
|
NormalError, ///< Error attached to a particular file
|
|
|
|
SoftError, ///< More like an information
|
|
|
|
|
|
|
|
Success, ///< The file was properly synced
|
2017-07-12 11:57:41 +03:00
|
|
|
|
|
|
|
/** Marks a conflict, old or new.
|
|
|
|
*
|
|
|
|
* With instruction:IGNORE: detected an old unresolved old conflict
|
|
|
|
* With instruction:CONFLICT: a new conflict this sync run
|
|
|
|
*/
|
|
|
|
Conflict,
|
|
|
|
|
2014-10-08 11:07:05 +04:00
|
|
|
FileIgnored, ///< The file is in the ignored list (or blacklisted with no retries left)
|
2019-06-03 18:50:16 +03:00
|
|
|
FileLocked, ///< The file is locked
|
2017-06-27 15:17:26 +03:00
|
|
|
Restoration, ///< The file was restored because what should have been done was not allowed
|
|
|
|
|
2021-04-08 10:09:29 +03:00
|
|
|
/**
|
|
|
|
* The filename is invalid on this platform and could not created.
|
|
|
|
*/
|
|
|
|
FileNameInvalid,
|
|
|
|
|
2017-07-12 13:38:53 +03:00
|
|
|
/** For errors that should only appear in the error view.
|
2017-06-27 15:17:26 +03:00
|
|
|
*
|
2017-07-12 13:38:53 +03:00
|
|
|
* Some errors also produce a summary message. Usually displaying that message is
|
|
|
|
* sufficient, but the individual errors should still appear in the issues tab.
|
2017-06-27 15:17:26 +03:00
|
|
|
*
|
2017-07-12 13:38:53 +03:00
|
|
|
* These errors do cause the sync to fail.
|
|
|
|
*
|
|
|
|
* A NormalError that isn't as prominent.
|
|
|
|
*/
|
|
|
|
DetailError,
|
|
|
|
|
|
|
|
/** For files whose errors were blacklisted
|
|
|
|
*
|
|
|
|
* If an file is blacklisted due to an error it isn't even reattempted. These
|
2018-03-27 16:42:09 +03:00
|
|
|
* errors should appear in the issues tab but should be silent otherwise.
|
2017-07-12 13:38:53 +03:00
|
|
|
*
|
2018-03-27 16:42:09 +03:00
|
|
|
* A SoftError caused by blacklisting.
|
2017-06-27 15:17:26 +03:00
|
|
|
*/
|
|
|
|
BlacklistedError
|
2013-10-04 17:13:36 +04:00
|
|
|
};
|
2018-07-10 11:21:45 +03:00
|
|
|
Q_ENUM(Status)
|
2013-10-04 17:13:36 +04:00
|
|
|
|
2019-01-21 13:19:45 +03:00
|
|
|
SyncJournalFileRecord toSyncJournalFileRecordWithInode(const QString &localFileName) const;
|
2017-08-30 12:17:23 +03:00
|
|
|
|
|
|
|
/** Creates a basic SyncFileItem from a DB record
|
|
|
|
*
|
|
|
|
* This is intended in particular for read-update-write cycles that need
|
|
|
|
* to go through a a SyncFileItem, like PollJob.
|
|
|
|
*/
|
|
|
|
static SyncFileItemPtr fromSyncJournalFileRecord(const SyncJournalFileRecord &rec);
|
|
|
|
|
|
|
|
|
2014-06-20 14:54:46 +04:00
|
|
|
SyncFileItem()
|
2017-12-14 17:08:53 +03:00
|
|
|
: _type(ItemTypeSkip)
|
2014-06-20 14:54:46 +04:00
|
|
|
, _direction(None)
|
2015-10-29 11:35:42 +03:00
|
|
|
, _serverHasIgnoredFiles(false)
|
|
|
|
, _hasBlacklistEntry(false)
|
|
|
|
, _errorMayBeBlacklisted(false)
|
|
|
|
, _status(NoStatus)
|
2016-08-15 15:17:51 +03:00
|
|
|
, _isRestoration(false)
|
2019-10-16 13:12:02 +03:00
|
|
|
, _isSelectiveSync(false)
|
2020-12-01 14:45:01 +03:00
|
|
|
, _isEncrypted(false)
|
2014-12-06 14:27:50 +03:00
|
|
|
{
|
|
|
|
}
|
2013-01-15 23:41:52 +04:00
|
|
|
|
2013-05-03 21:11:00 +04:00
|
|
|
friend bool operator==(const SyncFileItem &item1, const SyncFileItem &item2)
|
|
|
|
{
|
2015-02-19 15:13:45 +03:00
|
|
|
return item1._originalFile == item2._originalFile;
|
2013-05-03 21:11:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
friend bool operator<(const SyncFileItem &item1, const SyncFileItem &item2)
|
|
|
|
{
|
2013-05-15 17:22:20 +04:00
|
|
|
// Sort by destination
|
2015-02-12 21:15:55 +03:00
|
|
|
auto d1 = item1.destination();
|
|
|
|
auto d2 = item2.destination();
|
|
|
|
|
|
|
|
// But this we need to order it so the slash come first. It should be this order:
|
|
|
|
// "foo", "foo/bar", "foo-bar"
|
|
|
|
// This is important since we assume that the contents of a folder directly follows
|
|
|
|
// its contents
|
|
|
|
|
|
|
|
auto data1 = d1.constData();
|
|
|
|
auto data2 = d2.constData();
|
|
|
|
|
2015-10-05 06:20:09 +03:00
|
|
|
// Find the length of the largest prefix
|
2015-02-12 21:15:55 +03:00
|
|
|
int prefixL = 0;
|
|
|
|
auto minSize = std::min(d1.size(), d2.size());
|
|
|
|
while (prefixL < minSize && data1[prefixL] == data2[prefixL]) {
|
|
|
|
prefixL++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prefixL == d2.size())
|
|
|
|
return false;
|
2015-02-17 20:22:22 +03:00
|
|
|
if (prefixL == d1.size())
|
|
|
|
return true;
|
2015-02-12 21:15:55 +03:00
|
|
|
|
|
|
|
if (data1[prefixL] == '/')
|
|
|
|
return true;
|
|
|
|
if (data2[prefixL] == '/')
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return data1[prefixL] < data2[prefixL];
|
2013-01-15 23:41:52 +04:00
|
|
|
}
|
|
|
|
|
2013-05-15 17:22:20 +04:00
|
|
|
QString destination() const
|
|
|
|
{
|
2014-09-05 12:06:19 +04:00
|
|
|
if (!_renameTarget.isEmpty()) {
|
|
|
|
return _renameTarget;
|
|
|
|
}
|
|
|
|
return _file;
|
2013-05-15 17:22:20 +04:00
|
|
|
}
|
|
|
|
|
2013-02-14 19:25:00 +04:00
|
|
|
bool isEmpty() const
|
|
|
|
{
|
|
|
|
return _file.isEmpty();
|
|
|
|
}
|
|
|
|
|
2017-08-24 18:31:46 +03:00
|
|
|
bool isDirectory() const
|
|
|
|
{
|
2017-12-14 17:08:53 +03:00
|
|
|
return _type == ItemTypeDirectory;
|
2017-08-24 18:31:46 +03:00
|
|
|
}
|
|
|
|
|
2015-12-10 12:42:49 +03:00
|
|
|
/**
|
|
|
|
* True if the item had any kind of error.
|
|
|
|
*/
|
2014-10-13 19:23:42 +04:00
|
|
|
bool hasErrorStatus() const
|
|
|
|
{
|
|
|
|
return _status == SyncFileItem::SoftError
|
|
|
|
|| _status == SyncFileItem::NormalError
|
|
|
|
|| _status == SyncFileItem::FatalError
|
|
|
|
|| !_errorString.isEmpty();
|
|
|
|
}
|
|
|
|
|
2018-01-22 12:51:53 +03:00
|
|
|
/**
|
|
|
|
* Whether this item should appear on the issues tab.
|
|
|
|
*/
|
|
|
|
bool showInIssuesTab() const
|
|
|
|
{
|
|
|
|
return hasErrorStatus() || _status == SyncFileItem::Conflict;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether this item should appear on the protocol tab.
|
|
|
|
*/
|
|
|
|
bool showInProtocolTab() const
|
|
|
|
{
|
2019-10-10 14:21:28 +03:00
|
|
|
return (!showInIssuesTab() || _status == SyncFileItem::Restoration)
|
2018-01-22 12:51:53 +03:00
|
|
|
// Don't show conflicts that were resolved as "not a conflict after all"
|
|
|
|
&& !(_instruction == CSYNC_INSTRUCTION_CONFLICT && _status == SyncFileItem::Success);
|
|
|
|
}
|
|
|
|
|
2015-10-05 06:20:09 +03:00
|
|
|
// Variables useful for everybody
|
2019-02-08 14:21:25 +03:00
|
|
|
|
|
|
|
/** The syncfolder-relative filesystem path that the operation is about
|
|
|
|
*
|
|
|
|
* For rename operation this is the rename source and the target is in _renameTarget.
|
|
|
|
*/
|
2013-01-15 23:41:52 +04:00
|
|
|
QString _file;
|
2019-02-08 14:21:25 +03:00
|
|
|
|
|
|
|
/** for renames: the name _file should be renamed to
|
|
|
|
* for dehydrations: the name _file should become after dehydration (like adding a suffix)
|
|
|
|
* otherwise empty. Use destination() to find the sync target.
|
|
|
|
*/
|
2013-01-15 23:41:52 +04:00
|
|
|
QString _renameTarget;
|
2018-01-28 20:37:01 +03:00
|
|
|
|
2019-02-08 14:21:25 +03:00
|
|
|
/** The db-path of this item.
|
|
|
|
*
|
|
|
|
* This can easily differ from _file and _renameTarget if parts of the path were renamed.
|
|
|
|
*/
|
|
|
|
QString _originalFile;
|
|
|
|
|
2018-01-28 20:37:01 +03:00
|
|
|
/// Whether there's end to end encryption on this file.
|
|
|
|
/// If the file is encrypted, the _encryptedFilename is
|
|
|
|
/// the encrypted name on the server.
|
|
|
|
QString _encryptedFileName;
|
2019-02-08 14:21:25 +03:00
|
|
|
|
2017-12-14 17:08:53 +03:00
|
|
|
ItemType _type BITFIELD(3);
|
2016-12-08 17:56:26 +03:00
|
|
|
Direction _direction BITFIELD(3);
|
2015-07-13 16:41:11 +03:00
|
|
|
bool _serverHasIgnoredFiles BITFIELD(1);
|
2015-03-11 13:41:42 +03:00
|
|
|
|
|
|
|
/// Whether there's an entry in the blacklist table.
|
|
|
|
/// Note: that entry may have retries left, so this can be true
|
|
|
|
/// without the status being FileIgnored.
|
2015-03-12 14:56:43 +03:00
|
|
|
bool _hasBlacklistEntry BITFIELD(1);
|
2015-03-11 13:41:42 +03:00
|
|
|
|
2015-10-29 11:35:42 +03:00
|
|
|
/** If true and NormalError, this error may be blacklisted
|
|
|
|
*
|
|
|
|
* Note that non-local errors (httpErrorCode!=0) may also be
|
|
|
|
* blacklisted independently of this flag.
|
|
|
|
*/
|
|
|
|
bool _errorMayBeBlacklisted BITFIELD(1);
|
|
|
|
|
2015-10-05 06:20:09 +03:00
|
|
|
// Variables useful to report to the user
|
2015-03-12 14:56:43 +03:00
|
|
|
Status _status BITFIELD(4);
|
|
|
|
bool _isRestoration BITFIELD(1); // The original operation was forbidden, and this is a restoration
|
2019-10-16 13:12:02 +03:00
|
|
|
bool _isSelectiveSync BITFIELD(1); // The file is removed or ignored because it is in the selective sync list
|
2020-12-01 14:45:01 +03:00
|
|
|
bool _isEncrypted BITFIELD(1); // The file is E2EE or the content of the directory should be E2EE
|
2020-05-28 17:59:24 +03:00
|
|
|
quint16 _httpErrorCode = 0;
|
2017-09-19 11:53:51 +03:00
|
|
|
RemotePermissions _remotePerm;
|
2015-03-11 13:41:42 +03:00
|
|
|
QString _errorString; // Contains a string only in case of error
|
|
|
|
QByteArray _responseTimeStamp;
|
2018-04-04 17:27:08 +03:00
|
|
|
QByteArray _requestId; // X-Request-Id of the failed request
|
2020-05-28 17:59:24 +03:00
|
|
|
quint32 _affectedItems = 1; // the number of affected items by the operation on this item.
|
2015-03-11 13:41:42 +03:00
|
|
|
// usually this value is 1, but for removes on dirs, it might be much higher.
|
2013-10-04 17:13:36 +04:00
|
|
|
|
|
|
|
// Variables used by the propagator
|
2020-04-22 16:23:18 +03:00
|
|
|
SyncInstructions _instruction = CSYNC_INSTRUCTION_NONE;
|
2020-05-28 17:59:24 +03:00
|
|
|
time_t _modtime = 0;
|
2013-10-25 15:28:48 +04:00
|
|
|
QByteArray _etag;
|
2019-02-13 12:15:33 +03:00
|
|
|
qint64 _size = 0;
|
2020-05-28 17:59:24 +03:00
|
|
|
quint64 _inode = 0;
|
2014-03-24 15:21:44 +04:00
|
|
|
QByteArray _fileId;
|
2017-06-14 13:14:46 +03:00
|
|
|
|
2017-09-15 14:30:29 +03:00
|
|
|
// This is the value for the 'new' side, matching with _size and _modtime.
|
|
|
|
//
|
2017-06-14 13:14:46 +03:00
|
|
|
// When is this set, and is it the local or the remote checksum?
|
|
|
|
// - if mtime or size changed locally for *.eml files (local checksum)
|
|
|
|
// - for potential renames of local files (local checksum)
|
2017-09-15 14:30:29 +03:00
|
|
|
// - for conflicts (remote checksum)
|
2017-06-14 13:14:46 +03:00
|
|
|
QByteArray _checksumHeader;
|
|
|
|
|
2017-08-24 18:07:22 +03:00
|
|
|
// The size and modtime of the file getting overwritten (on the disk for downloads, on the server for uploads).
|
2019-02-13 12:15:33 +03:00
|
|
|
qint64 _previousSize = 0;
|
2020-05-28 17:59:24 +03:00
|
|
|
time_t _previousModtime = 0;
|
2017-08-24 18:07:22 +03:00
|
|
|
|
2014-06-03 13:50:13 +04:00
|
|
|
QString _directDownloadUrl;
|
|
|
|
QString _directDownloadCookies;
|
2013-01-15 23:41:52 +04:00
|
|
|
};
|
|
|
|
|
2015-04-15 16:19:11 +03:00
|
|
|
inline bool operator<(const SyncFileItemPtr &item1, const SyncFileItemPtr &item2)
|
|
|
|
{
|
|
|
|
return *item1 < *item2;
|
|
|
|
}
|
2013-05-03 21:11:00 +04:00
|
|
|
|
2020-08-12 16:23:11 +03:00
|
|
|
using SyncFileItemVector = QVector<SyncFileItemPtr>;
|
2013-01-15 23:41:52 +04:00
|
|
|
}
|
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
Q_DECLARE_METATYPE(OCC::SyncFileItem)
|
2017-01-25 13:12:38 +03:00
|
|
|
Q_DECLARE_METATYPE(OCC::SyncFileItemPtr)
|
2013-05-16 15:54:22 +04:00
|
|
|
|
2013-01-15 23:41:52 +04:00
|
|
|
#endif // SYNCFILEITEM_H
|