Пример #1
0
    void testFileRecord()
    {
        SyncJournalFileRecord record = _db.getFileRecord("nonexistant");
        QVERIFY(!record.isValid());

        record._path = "foo";
        record._inode = 1234;
        record._modtime = dropMsecs(QDateTime::currentDateTime());
        record._type = 5;
        record._etag = "789789";
        record._fileId = "abcd";
        record._remotePerm = "744";
        record._fileSize = 213089055;
        record._contentChecksum = "mychecksum";
        record._contentChecksumType = "MD5";
        QVERIFY(_db.setFileRecord(record));

        SyncJournalFileRecord storedRecord = _db.getFileRecord("foo");
        QVERIFY(storedRecord == record);

        // Update checksum
        record._contentChecksum = "newchecksum";
        record._contentChecksumType = "Adler32";
        _db.updateFileRecordChecksum("foo", record._contentChecksum, record._contentChecksumType);
        storedRecord = _db.getFileRecord("foo");
        QVERIFY(storedRecord == record);

        // Update metadata
        record._inode = 12345;
        record._modtime = dropMsecs(QDateTime::currentDateTime().addDays(1));
        record._type = 7;
        record._etag = "789FFF";
        record._fileId = "efg";
        record._remotePerm = "777";
        record._fileSize = 289055;
        _db.setFileRecordMetadata(record);
        storedRecord = _db.getFileRecord("foo");
        QVERIFY(storedRecord == record);

        QVERIFY(_db.deleteFileRecord("foo"));
        record = _db.getFileRecord("foo");
        QVERIFY(!record.isValid());
    }
Пример #2
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();
}
Пример #3
0
void PropagateRemoteMove::finalize()
{
    SyncJournalFileRecord oldRecord;
    propagator()->_journal->getFileRecord(_item->_originalFile, &oldRecord);
    // if reading from db failed still continue hoping that deleteFileRecord
    // reopens the db successfully.
    // The db is only queried to transfer the content checksum from the old
    // to the new record. It is not a problem to skip it here.
    propagator()->_journal->deleteFileRecord(_item->_originalFile);

    SyncFileItem newItem(*_item);
    newItem._type = _item->_type;
    if (oldRecord.isValid()) {
        newItem._checksumHeader = oldRecord._checksumHeader;
        if (newItem._size != oldRecord._fileSize) {
            qCWarning(lcPropagateRemoteMove) << "File sizes differ on server vs sync journal: " << newItem._size << oldRecord._fileSize;

            // the server might have claimed a different size, we take the old one from the DB
            newItem._size = oldRecord._fileSize;
        }
    }
    if (!propagator()->updateMetadata(newItem)) {
        done(SyncFileItem::FatalError, tr("Error writing metadata to the database"));
        return;
    }

    if (_item->isDirectory()) {
        propagator()->_renamedDirectories.insert(_item->_file, _item->_renameTarget);
        if (!adjustSelectiveSync(propagator()->_journal, _item->_file, _item->_renameTarget)) {
            done(SyncFileItem::FatalError, tr("Error writing metadata to the database"));
            return;
        }
    }

    propagator()->_journal->commit("Remote Rename");
    done(SyncFileItem::Success);
}
Пример #4
0
void PropagateRemoteMove::finalize()
{
    SyncJournalFileRecord oldRecord =
            _propagator->_journal->getFileRecord(_item->_originalFile);
    // if reading from db failed still continue hoping that deleteFileRecord
    // reopens the db successfully.
    // The db is only queried to transfer the content checksum from the old
    // to the new record. It is not a problem to skip it here.
    _propagator->_journal->deleteFileRecord(_item->_originalFile);

    SyncJournalFileRecord record(*_item, _propagator->getFilePath(_item->_renameTarget));
    record._path = _item->_renameTarget;
    if (oldRecord.isValid()) {
        record._contentChecksum = oldRecord._contentChecksum;
        record._contentChecksumType = oldRecord._contentChecksumType;
        if (record._fileSize != oldRecord._fileSize) {
            qDebug() << "Warning: file sizes differ on server vs csync_journal: " << record._fileSize << oldRecord._fileSize;
            record._fileSize = oldRecord._fileSize; // server might have claimed different size, we take the old one from the DB
        }
    }

    if (!_propagator->_journal->setFileRecord(record)) {
        done(SyncFileItem::FatalError, tr("Error writing metadata to the database"));
        return;
    }

    if (_item->_isDirectory) {
        if (!adjustSelectiveSync(_propagator->_journal, _item->_file, _item->_renameTarget)) {
            done(SyncFileItem::FatalError, tr("Error writing metadata to the database"));
            return;
        }
    }

    _propagator->_journal->commit("Remote Rename");
    done(SyncFileItem::Success);
}