Пример #1
0
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();
}