SyncFileStatus SyncFileStatusTracker::fileStatus(const QString& relativePath) { // normalization is required for OS X to match file names properly QString normalizedRelativePath = relativePath.normalized(QString::NormalizationForm_C); Q_ASSERT(!normalizedRelativePath.endsWith(QLatin1Char('/'))); if (normalizedRelativePath.isEmpty()) { // This is the root sync folder, it doesn't have an entry in the database and won't be walked by csync, so create one manually. return syncFileItemStatus(rootSyncFileItem()); } // The SyncEngine won't notify us at all for CSYNC_FILE_SILENTLY_EXCLUDED // and CSYNC_FILE_EXCLUDE_AND_REMOVE excludes. Even though it's possible // that the status of CSYNC_FILE_EXCLUDE_LIST excludes will change if the user // update the exclude list at runtime and doing it statically here removes // our ability to notify changes through the fileStatusChanged signal, // it's an acceptable compromize to treat all exclude types the same. if( _syncEngine->excludedFiles().isExcluded(_syncEngine->localPath() + normalizedRelativePath, _syncEngine->localPath(), _syncEngine->ignoreHiddenFiles()) ) { return SyncFileStatus(SyncFileStatus::StatusWarning); } if ( _dirtyPaths.contains(normalizedRelativePath) ) return SyncFileStatus::StatusSync; SyncFileItem* item = _syncEngine->findSyncItem(normalizedRelativePath); if (item) { return syncFileItemStatus(*item); } // If we're not currently syncing that file, look it up in the database to know if it's shared SyncJournalFileRecord rec = _syncEngine->journal()->getFileRecord(normalizedRelativePath); if (rec.isValid()) { return syncFileItemStatus(rec.toSyncFileItem()); } // Must be a new file, wait for the filesystem watcher to trigger a sync return SyncFileStatus(); }
void Folder::bubbleUpSyncResult() { // count new, removed and updated items int newItems = 0; int removedItems = 0; int updatedItems = 0; int ignoredItems = 0; int renamedItems = 0; SyncFileItem firstItemNew; SyncFileItem firstItemDeleted; SyncFileItem firstItemUpdated; SyncFileItem firstItemRenamed; Logger *logger = Logger::instance(); SyncRunFileLog syncFileLog; syncFileLog.start(path(), _engine ? _engine->stopWatch() : Utility::StopWatch() ); QElapsedTimer timer; timer.start(); foreach (const SyncFileItem &item, _syncResult.syncFileItemVector() ) { // Log the item syncFileLog.logItem( item ); // and process the item to the gui if( item._status == SyncFileItem::FatalError || item._status == SyncFileItem::NormalError ) { slotSyncError( tr("%1: %2").arg(item._file, item._errorString) ); logger->postOptionalGuiLog(item._file, item._errorString); } else { // add new directories or remove gone away dirs to the watcher if (item._isDirectory && item._instruction == CSYNC_INSTRUCTION_NEW ) { FolderMan::instance()->addMonitorPath( alias(), path()+item._file ); } if (item._isDirectory && item._instruction == CSYNC_INSTRUCTION_REMOVE ) { FolderMan::instance()->removeMonitorPath( alias(), path()+item._file ); } if (item._direction == SyncFileItem::Down) { switch (item._instruction) { case CSYNC_INSTRUCTION_NEW: newItems++; if (firstItemNew.isEmpty()) firstItemNew = item; break; case CSYNC_INSTRUCTION_REMOVE: removedItems++; if (firstItemDeleted.isEmpty()) firstItemDeleted = item; break; case CSYNC_INSTRUCTION_CONFLICT: case CSYNC_INSTRUCTION_SYNC: updatedItems++; if (firstItemUpdated.isEmpty()) firstItemUpdated = item; break; case CSYNC_INSTRUCTION_ERROR: qDebug() << "Got Instruction ERROR. " << _syncResult.errorString(); break; case CSYNC_INSTRUCTION_RENAME: if (firstItemRenamed.isEmpty()) { firstItemRenamed = item; } renamedItems++; break; default: // nothing. break; } } else if( item._direction == SyncFileItem::None ) { // ignored files counting. if( item._instruction == CSYNC_INSTRUCTION_IGNORE ) { ignoredItems++; } } } } syncFileLog.close(); qDebug() << "Processing result list and logging took " << timer.elapsed() << " Milliseconds."; _syncResult.setWarnCount(ignoredItems); createGuiLog( firstItemNew._file, SyncFileStatus(SyncFileStatus::STATUS_NEW), newItems ); createGuiLog( firstItemDeleted._file, SyncFileStatus(SyncFileStatus::STATUS_REMOVE), removedItems ); createGuiLog( firstItemUpdated._file, SyncFileStatus(SyncFileStatus::STATUS_UPDATED), updatedItems ); if( !firstItemRenamed.isEmpty() ) { SyncFileStatus status(SyncFileStatus::STATUS_RENAME); // if the path changes it's rather a move QDir renTarget = QFileInfo(firstItemRenamed._renameTarget).dir(); QDir renSource = QFileInfo(firstItemRenamed._file).dir(); if(renTarget != renSource) { status.set(SyncFileStatus::STATUS_MOVE); } createGuiLog( firstItemRenamed._file, status, renamedItems, firstItemRenamed._renameTarget ); } qDebug() << "OO folder slotSyncFinished: result: " << int(_syncResult.status()); }