Remove SyncFileItem::_isDirectory

It's always equivalent to _type == SyncFileItem::Directory.
This commit is contained in:
Jocelyn Turcotte 2017-08-24 17:31:46 +02:00 committed by Roeland Jago Douma
parent 85a93efe51
commit 0f21ed6a5b
No known key found for this signature in database
GPG key ID: F941078878347C0C
13 changed files with 32 additions and 31 deletions

View file

@ -840,10 +840,10 @@ void Folder::slotTransmissionProgress(const ProgressInfo &pi)
void Folder::slotItemCompleted(const SyncFileItemPtr &item) void Folder::slotItemCompleted(const SyncFileItemPtr &item)
{ {
// add new directories or remove gone away dirs to the watcher // add new directories or remove gone away dirs to the watcher
if (item->_isDirectory && item->_instruction == CSYNC_INSTRUCTION_NEW) { if (item->isDirectory() && item->_instruction == CSYNC_INSTRUCTION_NEW) {
FolderMan::instance()->addMonitorPath(alias(), path() + item->_file); FolderMan::instance()->addMonitorPath(alias(), path() + item->_file);
} }
if (item->_isDirectory && item->_instruction == CSYNC_INSTRUCTION_REMOVE) { if (item->isDirectory() && item->_instruction == CSYNC_INSTRUCTION_REMOVE) {
FolderMan::instance()->removeMonitorPath(alias(), path() + item->_file); FolderMan::instance()->removeMonitorPath(alias(), path() + item->_file);
} }

View file

@ -291,7 +291,7 @@ bool PropagateItemJob::checkForProblemsWithShared(int httpStatusCode, const QStr
PropagateItemJob *newJob = NULL; PropagateItemJob *newJob = NULL;
if (httpStatusCode == 403 && propagator()->isInSharedDirectory(_item->_file)) { if (httpStatusCode == 403 && propagator()->isInSharedDirectory(_item->_file)) {
if (!_item->_isDirectory) { if (!_item->isDirectory()) {
SyncFileItemPtr downloadItem(new SyncFileItem(*_item)); SyncFileItemPtr downloadItem(new SyncFileItem(*_item));
if (downloadItem->_instruction == CSYNC_INSTRUCTION_NEW if (downloadItem->_instruction == CSYNC_INSTRUCTION_NEW
|| downloadItem->_instruction == CSYNC_INSTRUCTION_TYPE_CHANGE) { || downloadItem->_instruction == CSYNC_INSTRUCTION_TYPE_CHANGE) {
@ -363,7 +363,7 @@ PropagateItemJob *OwncloudPropagator::createJob(const SyncFileItemPtr &item)
return new PropagateRemoteDelete(this, item); return new PropagateRemoteDelete(this, item);
case CSYNC_INSTRUCTION_NEW: case CSYNC_INSTRUCTION_NEW:
case CSYNC_INSTRUCTION_TYPE_CHANGE: case CSYNC_INSTRUCTION_TYPE_CHANGE:
if (item->_isDirectory) { if (item->isDirectory()) {
if (item->_direction == SyncFileItem::Down) { if (item->_direction == SyncFileItem::Down) {
auto job = new PropagateLocalMkdir(this, item); auto job = new PropagateLocalMkdir(this, item);
job->setDeleteExistingFile(deleteExisting); job->setDeleteExistingFile(deleteExisting);
@ -439,7 +439,7 @@ void OwncloudPropagator::start(const SyncFileItemVector &items)
delDirJob->increaseAffectedCount(); delDirJob->increaseAffectedCount();
} }
continue; continue;
} else if (item->_isDirectory } else if (item->isDirectory()
&& (item->_instruction == CSYNC_INSTRUCTION_NEW && (item->_instruction == CSYNC_INSTRUCTION_NEW
|| item->_instruction == CSYNC_INSTRUCTION_TYPE_CHANGE)) { || item->_instruction == CSYNC_INSTRUCTION_TYPE_CHANGE)) {
// create a new directory within a deleted directory? That can happen if the directory // create a new directory within a deleted directory? That can happen if the directory
@ -463,7 +463,7 @@ void OwncloudPropagator::start(const SyncFileItemVector &items)
directories.pop(); directories.pop();
} }
if (item->_isDirectory) { if (item->isDirectory()) {
PropagateDirectory *dir = new PropagateDirectory(this, item); PropagateDirectory *dir = new PropagateDirectory(this, item);
if (item->_instruction == CSYNC_INSTRUCTION_TYPE_CHANGE if (item->_instruction == CSYNC_INSTRUCTION_TYPE_CHANGE

View file

@ -103,7 +103,7 @@ public:
/** Return true if the size needs to be taken in account in the total amount of time */ /** Return true if the size needs to be taken in account in the total amount of time */
static inline bool isSizeDependent(const SyncFileItem &item) static inline bool isSizeDependent(const SyncFileItem &item)
{ {
return !item._isDirectory && (item._instruction == CSYNC_INSTRUCTION_CONFLICT return !item.isDirectory() && (item._instruction == CSYNC_INSTRUCTION_CONFLICT
|| item._instruction == CSYNC_INSTRUCTION_SYNC || item._instruction == CSYNC_INSTRUCTION_SYNC
|| item._instruction == CSYNC_INSTRUCTION_NEW || item._instruction == CSYNC_INSTRUCTION_NEW
|| item._instruction == CSYNC_INSTRUCTION_TYPE_CHANGE); || item._instruction == CSYNC_INSTRUCTION_TYPE_CHANGE);

View file

@ -120,7 +120,7 @@ void PropagateRemoteDelete::slotDeleteJobFinished()
return; return;
} }
propagator()->_journal->deleteFileRecord(_item->_originalFile, _item->_isDirectory); propagator()->_journal->deleteFileRecord(_item->_originalFile, _item->isDirectory());
propagator()->_journal->commit("Remote Remove"); propagator()->_journal->commit("Remote Remove");
done(SyncFileItem::Success); done(SyncFileItem::Success);
} }

View file

@ -54,7 +54,7 @@ public:
void start() Q_DECL_OVERRIDE; void start() Q_DECL_OVERRIDE;
void abort() Q_DECL_OVERRIDE; void abort() Q_DECL_OVERRIDE;
bool isLikelyFinishedQuickly() Q_DECL_OVERRIDE { return !_item->_isDirectory; } bool isLikelyFinishedQuickly() Q_DECL_OVERRIDE { return !_item->isDirectory(); }
private slots: private slots:
void slotDeleteJobFinished(); void slotDeleteJobFinished();

View file

@ -187,7 +187,7 @@ void PropagateRemoteMove::finalize()
return; return;
} }
if (_item->_isDirectory) { if (_item->isDirectory()) {
if (!adjustSelectiveSync(propagator()->_journal, _item->_file, _item->_renameTarget)) { if (!adjustSelectiveSync(propagator()->_journal, _item->_file, _item->_renameTarget)) {
done(SyncFileItem::FatalError, tr("Error writing metadata to the database")); done(SyncFileItem::FatalError, tr("Error writing metadata to the database"));
return; return;

View file

@ -57,7 +57,7 @@ public:
} }
void start() Q_DECL_OVERRIDE; void start() Q_DECL_OVERRIDE;
void abort() Q_DECL_OVERRIDE; void abort() Q_DECL_OVERRIDE;
JobParallelism parallelism() Q_DECL_OVERRIDE { return _item->_isDirectory ? WaitForFinished : FullParallelism; } JobParallelism parallelism() Q_DECL_OVERRIDE { return _item->isDirectory() ? WaitForFinished : FullParallelism; }
/** /**
* Rename the directory in the selective sync list * Rename the directory in the selective sync list

View file

@ -121,7 +121,7 @@ void PropagateLocalRemove::start()
return; return;
} }
if (_item->_isDirectory) { if (_item->isDirectory()) {
if (QDir(filename).exists() && !removeRecursively(QString())) { if (QDir(filename).exists() && !removeRecursively(QString())) {
done(SyncFileItem::NormalError, _error); done(SyncFileItem::NormalError, _error);
return; return;
@ -135,7 +135,7 @@ void PropagateLocalRemove::start()
} }
} }
propagator()->reportProgress(*_item, 0); propagator()->reportProgress(*_item, 0);
propagator()->_journal->deleteFileRecord(_item->_originalFile, _item->_isDirectory); propagator()->_journal->deleteFileRecord(_item->_originalFile, _item->isDirectory());
propagator()->_journal->commit("Local remove"); propagator()->_journal->commit("Local remove");
done(SyncFileItem::Success); done(SyncFileItem::Success);
} }
@ -245,7 +245,7 @@ void PropagateLocalRename::start()
record._checksumHeader = oldRecord._checksumHeader; record._checksumHeader = oldRecord._checksumHeader;
} }
if (!_item->_isDirectory) { // Directories are saved at the end if (!_item->isDirectory()) { // Directories are saved at the end
if (!propagator()->_journal->setFileRecord(record)) { if (!propagator()->_journal->setFileRecord(record)) {
done(SyncFileItem::FatalError, tr("Error writing metadata to the database")); done(SyncFileItem::FatalError, tr("Error writing metadata to the database"));
return; return;

View file

@ -91,6 +91,6 @@ public:
{ {
} }
void start() Q_DECL_OVERRIDE; void start() Q_DECL_OVERRIDE;
JobParallelism parallelism() Q_DECL_OVERRIDE { return _item->_isDirectory ? WaitForFinished : FullParallelism; } JobParallelism parallelism() Q_DECL_OVERRIDE { return _item->isDirectory() ? WaitForFinished : FullParallelism; }
}; };
} }

View file

@ -564,7 +564,6 @@ int SyncEngine::treewalkFile(csync_file_stat_t *file, csync_file_stat_t *other,
dir = SyncFileItem::None; dir = SyncFileItem::None;
// For directories, metadata-only updates will be done after all their files are propagated. // For directories, metadata-only updates will be done after all their files are propagated.
if (!isDirectory) { if (!isDirectory) {
item->_isDirectory = isDirectory;
emit syncItemDiscovered(*item); emit syncItemDiscovered(*item);
// Update the database now already: New remote fileid or Etag or RemotePerm // Update the database now already: New remote fileid or Etag or RemotePerm
@ -655,7 +654,6 @@ int SyncEngine::treewalkFile(csync_file_stat_t *file, csync_file_stat_t *other,
} }
item->_direction = dir; item->_direction = dir;
item->_isDirectory = isDirectory;
if (instruction != CSYNC_INSTRUCTION_NONE) { if (instruction != CSYNC_INSTRUCTION_NONE) {
// check for blacklisting of this item. // check for blacklisting of this item.
// if the item is on blacklist, the instruction was set to ERROR // if the item is on blacklist, the instruction was set to ERROR
@ -1196,7 +1194,7 @@ void SyncEngine::checkForPermission(SyncFileItemVector &syncItems)
(*it)->_status = SyncFileItem::FileIgnored; (*it)->_status = SyncFileItem::FileIgnored;
(*it)->_errorString = tr("Ignored because of the \"choose what to sync\" blacklist"); (*it)->_errorString = tr("Ignored because of the \"choose what to sync\" blacklist");
if ((*it)->_isDirectory) { if ((*it)->isDirectory()) {
auto it_base = it; auto it_base = it;
for (SyncFileItemVector::iterator it_next = it + 1; it_next != syncItems.end() && (*it_next)->_file.startsWith(path); ++it_next) { for (SyncFileItemVector::iterator it_next = it + 1; it_next != syncItems.end() && (*it_next)->_file.startsWith(path); ++it_next) {
it = it_next; it = it_next;
@ -1221,7 +1219,7 @@ void SyncEngine::checkForPermission(SyncFileItemVector &syncItems)
if (parent_it == syncItems.end() || (*parent_it)->destination() != parentDir) { if (parent_it == syncItems.end() || (*parent_it)->destination() != parentDir) {
break; break;
} }
ASSERT((*parent_it)->_isDirectory); ASSERT((*parent_it)->isDirectory());
if ((*parent_it)->_instruction != CSYNC_INSTRUCTION_IGNORE) { if ((*parent_it)->_instruction != CSYNC_INSTRUCTION_IGNORE) {
break; // already changed break; // already changed
} }
@ -1249,7 +1247,7 @@ void SyncEngine::checkForPermission(SyncFileItemVector &syncItems)
if (perms.isNull()) { if (perms.isNull()) {
// No permissions set // No permissions set
break; break;
} else if ((*it)->_isDirectory && !perms.contains("K")) { } else if ((*it)->isDirectory() && !perms.contains("K")) {
qCWarning(lcEngine) << "checkForPermission: ERROR" << (*it)->_file; qCWarning(lcEngine) << "checkForPermission: ERROR" << (*it)->_file;
(*it)->_instruction = CSYNC_INSTRUCTION_ERROR; (*it)->_instruction = CSYNC_INSTRUCTION_ERROR;
(*it)->_status = SyncFileItem::NormalError; (*it)->_status = SyncFileItem::NormalError;
@ -1271,7 +1269,7 @@ void SyncEngine::checkForPermission(SyncFileItemVector &syncItems)
(*it)->_errorString = tr("Not allowed because you don't have permission to add parent folder"); (*it)->_errorString = tr("Not allowed because you don't have permission to add parent folder");
} }
} else if (!(*it)->_isDirectory && !perms.contains("C")) { } else if (!(*it)->isDirectory() && !perms.contains("C")) {
qCWarning(lcEngine) << "checkForPermission: ERROR" << (*it)->_file; qCWarning(lcEngine) << "checkForPermission: ERROR" << (*it)->_file;
(*it)->_instruction = CSYNC_INSTRUCTION_ERROR; (*it)->_instruction = CSYNC_INSTRUCTION_ERROR;
(*it)->_status = SyncFileItem::NormalError; (*it)->_status = SyncFileItem::NormalError;
@ -1318,7 +1316,7 @@ void SyncEngine::checkForPermission(SyncFileItemVector &syncItems)
(*it)->_isRestoration = true; (*it)->_isRestoration = true;
(*it)->_errorString = tr("Not allowed to remove, restoring"); (*it)->_errorString = tr("Not allowed to remove, restoring");
if ((*it)->_isDirectory) { if ((*it)->isDirectory()) {
// restore all sub items // restore all sub items
for (SyncFileItemVector::iterator it_next = it + 1; for (SyncFileItemVector::iterator it_next = it + 1;
it_next != syncItems.end() && (*it_next)->_file.startsWith(path); ++it_next) { it_next != syncItems.end() && (*it_next)->_file.startsWith(path); ++it_next) {
@ -1345,7 +1343,7 @@ void SyncEngine::checkForPermission(SyncFileItemVector &syncItems)
// not delete permission we fast forward the iterator and leave the // not delete permission we fast forward the iterator and leave the
// delete jobs intact. It is not physically tried to remove this files // delete jobs intact. It is not physically tried to remove this files
// underneath, propagator sees that. // underneath, propagator sees that.
if ((*it)->_isDirectory) { if ((*it)->isDirectory()) {
// put a more descriptive message if a top level share dir really is removed. // put a more descriptive message if a top level share dir really is removed.
if (it == syncItems.begin() || !(path.startsWith((*(it - 1))->_file))) { if (it == syncItems.begin() || !(path.startsWith((*(it - 1))->_file))) {
(*it)->_errorString = tr("Local files and share folder removed."); (*it)->_errorString = tr("Local files and share folder removed.");
@ -1375,9 +1373,9 @@ void SyncEngine::checkForPermission(SyncFileItemVector &syncItems)
if (isRename || destPerms.isNull()) { if (isRename || destPerms.isNull()) {
// no need to check for the destination dir permission // no need to check for the destination dir permission
destinationOK = true; destinationOK = true;
} else if ((*it)->_isDirectory && !destPerms.contains("K")) { } else if ((*it)->isDirectory() && !destPerms.contains("K")) {
destinationOK = false; destinationOK = false;
} else if (!(*it)->_isDirectory && !destPerms.contains("C")) { } else if (!(*it)->isDirectory() && !destPerms.contains("C")) {
destinationOK = false; destinationOK = false;
} }
@ -1398,7 +1396,7 @@ void SyncEngine::checkForPermission(SyncFileItemVector &syncItems)
#ifdef OWNCLOUD_RESTORE_RENAME /* We don't like the idea of renaming behind user's back, as the user may be working with the files */ #ifdef OWNCLOUD_RESTORE_RENAME /* We don't like the idea of renaming behind user's back, as the user may be working with the files */
if (!sourceOK && (!destinationOK || isRename) if (!sourceOK && (!destinationOK || isRename)
// (not for directory because that's more complicated with the contents that needs to be adjusted) // (not for directory because that's more complicated with the contents that needs to be adjusted)
&& !(*it)->_isDirectory) { && !(*it)->isDirectory()) {
// Both the source and the destination won't allow move. Move back to the original // Both the source and the destination won't allow move. Move back to the original
std::swap((*it)->_file, (*it)->_renameTarget); std::swap((*it)->_file, (*it)->_renameTarget);
(*it)->_direction = SyncFileItem::Down; (*it)->_direction = SyncFileItem::Down;
@ -1426,7 +1424,7 @@ void SyncEngine::checkForPermission(SyncFileItemVector &syncItems)
_anotherSyncNeeded = ImmediateFollowUp; _anotherSyncNeeded = ImmediateFollowUp;
if ((*it)->_isDirectory) { if ((*it)->isDirectory()) {
for (SyncFileItemVector::iterator it_next = it + 1; for (SyncFileItemVector::iterator it_next = it + 1;
it_next != syncItems.end() && (*it_next)->destination().startsWith(path); ++it_next) { it_next != syncItems.end() && (*it_next)->destination().startsWith(path); ++it_next) {
it = it_next; it = it_next;

View file

@ -89,7 +89,6 @@ public:
SyncFileItem() SyncFileItem()
: _type(UnknownType) : _type(UnknownType)
, _direction(None) , _direction(None)
, _isDirectory(false)
, _serverHasIgnoredFiles(false) , _serverHasIgnoredFiles(false)
, _hasBlacklistEntry(false) , _hasBlacklistEntry(false)
, _errorMayBeBlacklisted(false) , _errorMayBeBlacklisted(false)
@ -158,6 +157,11 @@ public:
return _file.isEmpty(); return _file.isEmpty();
} }
bool isDirectory() const
{
return _type == SyncFileItem::Directory;
}
/** /**
* True if the item had any kind of error. * True if the item had any kind of error.
* *
@ -179,7 +183,6 @@ public:
QString _renameTarget; QString _renameTarget;
Type _type BITFIELD(3); Type _type BITFIELD(3);
Direction _direction BITFIELD(3); Direction _direction BITFIELD(3);
bool _isDirectory BITFIELD(1);
bool _serverHasIgnoredFiles BITFIELD(1); bool _serverHasIgnoredFiles BITFIELD(1);
/// Whether there's an entry in the blacklist table. /// Whether there's an entry in the blacklist table.

View file

@ -132,7 +132,7 @@ void SyncResult::processCompletedItem(const SyncFileItemPtr &item)
_foundFilesNotSynced = true; _foundFilesNotSynced = true;
} }
if (item->_isDirectory && (item->_instruction == CSYNC_INSTRUCTION_NEW if (item->isDirectory() && (item->_instruction == CSYNC_INSTRUCTION_NEW
|| item->_instruction == CSYNC_INSTRUCTION_TYPE_CHANGE || item->_instruction == CSYNC_INSTRUCTION_TYPE_CHANGE
|| item->_instruction == CSYNC_INSTRUCTION_REMOVE || item->_instruction == CSYNC_INSTRUCTION_REMOVE
|| item->_instruction == CSYNC_INSTRUCTION_RENAME)) { || item->_instruction == CSYNC_INSTRUCTION_RENAME)) {

View file

@ -309,7 +309,7 @@ private slots:
QSet<QString> seen; QSet<QString> seen;
for(const QList<QVariant> &args : completeSpy) { for(const QList<QVariant> &args : completeSpy) {
auto item = args[0].value<SyncFileItemPtr>(); auto item = args[0].value<SyncFileItemPtr>();
qDebug() << item->_file << item->_isDirectory << item->_status; qDebug() << item->_file << item->isDirectory() << item->_status;
QVERIFY(!seen.contains(item->_file)); // signal only sent once per item QVERIFY(!seen.contains(item->_file)); // signal only sent once per item
seen.insert(item->_file); seen.insert(item->_file);
if (item->_file == "Y/Z/d2") { if (item->_file == "Y/Z/d2") {