diff options
author | Camila San <hello@camila.codes> | 2019-07-19 22:31:15 +0300 |
---|---|---|
committer | Camila San <hello@camila.codes> | 2019-07-19 22:31:56 +0300 |
commit | d3b5c0448e6fcdc0fb3ac3b8384229c882ee72ce (patch) | |
tree | b49405a13399620f098753922e5fb6dcb2bf6220 | |
parent | f46cfb7003414c37d4ec8ad061520c45548de7c1 (diff) |
It fixes everything.filestreaming-v9
Signed-off-by: Camila San <hello@camila.codes>
-rw-r--r-- | src/csync/csync.cpp | 67 | ||||
-rw-r--r-- | src/csync/csync_reconcile.cpp | 12 | ||||
-rw-r--r-- | src/csync/csync_update.cpp | 8 | ||||
-rw-r--r-- | src/gui/syncwrapper.cpp | 72 | ||||
-rw-r--r-- | src/gui/vfs_windows.cpp | 10 | ||||
-rw-r--r-- | src/libsync/syncengine.cpp | 57 |
6 files changed, 174 insertions, 52 deletions
diff --git a/src/csync/csync.cpp b/src/csync/csync.cpp index d923850dc..4f1090c74 100644 --- a/src/csync/csync.cpp +++ b/src/csync/csync.cpp @@ -50,6 +50,9 @@ #include "common/syncjournalfilerecord.h" #include <common/asserts.h> +#include <QFile> +#include <QTextStream> + Q_LOGGING_CATEGORY(lcCSync, "sync.csync.csync", QtInfoMsg) csync_s::csync_s(const char *localUri, OCC::SyncJournalDb *statedb) @@ -515,6 +518,25 @@ bool cysnc_update_file(CSYNC *ctx, const char *absolutePath, const QByteArray &r csync_vio_closedir(ctx, dh); qCDebug(lcCSync, " <= Closing walk for %s with read_from_db %d", absolutePath, read_from_db); + qInstallMessageHandler([](QtMsgType type, const QMessageLogContext &, const QString & msg) { + QFile outFile("C:/Nextcloud/tree.txt"); + outFile.open(QIODevice::WriteOnly | QIODevice::Append); + QTextStream ts(&outFile); + ts << msg << endl;}); + std::unordered_map<ByteArrayRef, std::unique_ptr<csync_file_stat_t>, ByteArrayRefHash>::iterator it = ctx->local.files.begin(); + qDebug() << "0 DISCOVERY/UPDATE cysnc_update_file: Local file tree in the end #########"; + while (it != ctx->local.files.end()) { + qDebug() << "localFile->file_id " << it->second->file_id; + qDebug() << "localFile->inode " << it->second->inode; + qDebug() << "localFile->etag " << it->second->etag; + qDebug() << "localFile->checksumHeader " << it->second->checksumHeader; + qDebug() << "localFile->path " << it->second->path; + qDebug() << "localFile->is_fuse_created_file " << it->second->is_fuse_created_file; + qDebug() << "localFile->instruction " << csync_instruction_str(it->second->instruction); + it++; + } + qDebug() << "######################################################" << "\n"; + qInstallMessageHandler([](QtMsgType type, const QMessageLogContext &, const QString & msg) {}); ctx->current = REMOTE_REPLICA; @@ -532,17 +554,25 @@ bool cysnc_update_is_fuse_created_file(CSYNC *ctx, const QByteArray &relativePat if (ctx->local.files.findFile(relativePath)) { ctx->local.files.findFile(relativePath)->is_fuse_created_file = is_fuse_created_file; - //std::unordered_map<ByteArrayRef, std::unique_ptr<csync_file_stat_t>, ByteArrayRefHash>::iterator it = ctx->local.files.begin(); - qDebug() << "cysnc_update_is_fuse_created_file ######################################################" << relativePath << ctx->local.files.findFile(relativePath)->is_fuse_created_file; - //while (it != ctx->local.files.end()) { - // qDebug() << "localFile->file_id " << it->second->file_id; - // qDebug() << "localFile->path " << it->second->path; - // qDebug() << "localFile->original_path " << it->second->original_path; - // qDebug() << "localFile->instruction " << it->second->instruction; - // qDebug() << "localFile->is_fuse_created_file " << it->second->is_fuse_created_file; - // it++; - //} - //qDebug() << "######################################################"; + qInstallMessageHandler([](QtMsgType type, const QMessageLogContext &, const QString & msg) { + QFile outFile("C:/Nextcloud/tree.txt"); + outFile.open(QIODevice::WriteOnly | QIODevice::Append); + QTextStream ts(&outFile); + ts << msg << endl;}); + std::unordered_map<ByteArrayRef, std::unique_ptr<csync_file_stat_t>, ByteArrayRefHash>::iterator it = ctx->local.files.begin(); + qDebug() << ">> JUST CHECKING cysnc_update_is_fuse_created_file #########"; + while (it != ctx->local.files.end()) { + qDebug() << "localFile->file_id " << it->second->file_id; + qDebug() << "localFile->inode " << it->second->inode; + qDebug() << "localFile->etag " << it->second->etag; + qDebug() << "localFile->checksumHeader " << it->second->checksumHeader; + qDebug() << "localFile->path " << it->second->path; + qDebug() << "localFile->is_fuse_created_file " << it->second->is_fuse_created_file; + qDebug() << "localFile->instruction " << it->second->is_fuse_created_file; + it++; + } + qDebug() << "######################################################" << "\n"; + qInstallMessageHandler([](QtMsgType type, const QMessageLogContext &, const QString & msg) {}); return true; @@ -556,16 +586,25 @@ bool cysnc_update_path(CSYNC *ctx, const QByteArray &relativeOldPath, const QByt if (ctx->local.files.findFile(relativeOldPath)) { ctx->local.files.findFile(relativeOldPath)->path = relativeNewPath; + qInstallMessageHandler([](QtMsgType type, const QMessageLogContext &, const QString & msg) { + QFile outFile("C:/Nextcloud/tree.txt"); + outFile.open(QIODevice::WriteOnly | QIODevice::Append); + QTextStream ts(&outFile); + ts << msg << "\n" << endl;}); + qDebug() << "'DISCOVERY' PHASE cysnc_update_path: Local file tree after updating one file #######"; std::unordered_map<ByteArrayRef, std::unique_ptr<csync_file_stat_t>, ByteArrayRefHash>::iterator it = ctx->local.files.begin(); - qDebug() << "cysnc_update_path ######################################################" << relativeOldPath << ctx->local.files.findFile(relativeOldPath)->path; while (it != ctx->local.files.end()) { qDebug() << "localFile->file_id " << it->second->file_id; + qDebug() << "localFile->etag " << it->second->etag; + qDebug() << "localFile->checksumHeader " << it->second->checksumHeader; + qDebug() << "localFile->inode " << it->second->inode; qDebug() << "localFile->path " << it->second->path; + qDebug() << "localFile->is_fuse_created_file " << it->second->is_fuse_created_file; qDebug() << "localFile->instruction " << csync_instruction_str(it->second->instruction); it++; } - qDebug() << "######################################################"; - + qDebug() << "####################################################" << "\n"; + qInstallMessageHandler([](QtMsgType type, const QMessageLogContext &, const QString & msg) {}); return true; } diff --git a/src/csync/csync_reconcile.cpp b/src/csync/csync_reconcile.cpp index 2656baa6e..84deea024 100644 --- a/src/csync/csync_reconcile.cpp +++ b/src/csync/csync_reconcile.cpp @@ -409,13 +409,19 @@ static void _csync_merge_algorithm_visitor(csync_file_stat_t *cur, CSYNC * ctx) if (cur->type != other->type) { // If the type of the entity changed, it's like NEW, but // needs to delete the other entity first. - cur->instruction = CSYNC_INSTRUCTION_TYPE_CHANGE; + if(ctx->current == REMOTE_REPLICA && other->is_fuse_created_file) + cur->instruction = CSYNC_INSTRUCTION_NONE; + else cur->instruction = CSYNC_INSTRUCTION_TYPE_CHANGE; other->instruction = CSYNC_INSTRUCTION_NONE; } else if (cur->type == ItemTypeDirectory) { - cur->instruction = CSYNC_INSTRUCTION_UPDATE_METADATA; + if(ctx->current == REMOTE_REPLICA && other->is_fuse_created_file) + cur->instruction = CSYNC_INSTRUCTION_NONE; + else cur->instruction = CSYNC_INSTRUCTION_UPDATE_METADATA; other->instruction = CSYNC_INSTRUCTION_NONE; } else { - cur->instruction = CSYNC_INSTRUCTION_SYNC; + if(ctx->current == REMOTE_REPLICA && other->is_fuse_created_file) + cur->instruction = CSYNC_INSTRUCTION_NONE; + else cur->instruction = CSYNC_INSTRUCTION_SYNC; other->instruction = CSYNC_INSTRUCTION_NONE; } break; diff --git a/src/csync/csync_update.cpp b/src/csync/csync_update.cpp index dd8d25a05..573c295b0 100644 --- a/src/csync/csync_update.cpp +++ b/src/csync/csync_update.cpp @@ -284,12 +284,14 @@ static int _csync_detect_update(CSYNC *ctx, std::unique_ptr<csync_file_stat_t> f if( ctx->current == REMOTE_REPLICA ) { fs->has_ignored_files = base._serverHasIgnoredFiles; } - if (metadata_differ) { + if (metadata_differ) { /* file id or permissions has changed. Which means we need to update them in the DB. */ qCDebug(lcUpdate, "Need to update metadata for: %s", fs->path.constData()); - if(!fs->is_fuse_created_file) fs->instruction = CSYNC_INSTRUCTION_UPDATE_METADATA; + //if(!fs->is_fuse_created_file) + fs->instruction = CSYNC_INSTRUCTION_UPDATE_METADATA; } else { - fs->instruction = CSYNC_INSTRUCTION_NONE; + //if(!fs->is_fuse_created_file) + fs->instruction = CSYNC_INSTRUCTION_NONE; } } else { /* check if it's a file and has been renamed */ diff --git a/src/gui/syncwrapper.cpp b/src/gui/syncwrapper.cpp index 8e5aa93c3..b0579c0f5 100644 --- a/src/gui/syncwrapper.cpp +++ b/src/gui/syncwrapper.cpp @@ -1,7 +1,7 @@ #include "syncwrapper.h" #include "socketapi.h" #include "csync/vio/csync_vio_local.h" - +#include "csync/csync_util.h" #include <qdir.h> namespace OCC { @@ -24,24 +24,38 @@ namespace OCC { Folder *folderForPath = FolderMan::instance()->folderForPath(localPath); - QString folderRelativePath(""); - if (folderForPath) - folderRelativePath = localPath.mid(folderForPath->cleanPath().length() + 1); + //QString folderRelativePath(""); + //if (folderForPath) + // folderRelativePath = localPath.mid(folderForPath->cleanPath().length() + 1); - return folderRelativePath; + return folderForPath->cleanPath(); } void SyncWrapper::updateFileTree(int type, const QString path) { - //csync_instructions_e instruction = (type == 2) ? CSYNC_INSTRUCTION_NEW : CSYNC_INSTRUCTION_IGNORE; - - if (SyncJournalDb::instance()->getSyncMode(getRelativePath(path)) != SyncJournalDb::SyncMode::SYNCMODE_OFFLINE) { - FolderMan::instance()->currentSyncFolder()->updateLocalFileTree(getRelativePath(path), CSYNC_INSTRUCTION_IGNORE); + //QString folderRelativePath = getRelativePath(path); + QString folderRelativePath = path; + qInstallMessageHandler([](QtMsgType type, const QMessageLogContext &, const QString & msg) { + QFile outFile("C:/Nextcloud/tree.txt"); + outFile.open(QIODevice::WriteOnly | QIODevice::Append); + QTextStream ts(&outFile); + ts << msg << endl;}); + + qDebug() << ">> SyncWrapper::updateFileTree #######" << path; + qDebug() << "path: " << path; + qDebug() << "folderRelativePath: " << folderRelativePath; + qDebug() << "sync mode: " << SyncJournalDb::instance()->getSyncMode(folderRelativePath); + + if (SyncJournalDb::instance()->getSyncMode(folderRelativePath) != SyncJournalDb::SyncMode::SYNCMODE_OFFLINE) { + qDebug() << "instruction: " << csync_instruction_str(CSYNC_INSTRUCTION_IGNORE); + FolderMan::instance()->currentSyncFolder()->updateLocalFileTree(folderRelativePath, CSYNC_INSTRUCTION_IGNORE); } else { - FolderMan::instance()->currentSyncFolder()->updateLocalFileTree(getRelativePath(path), CSYNC_INSTRUCTION_NEW); + qDebug() << "instruction: " << csync_instruction_str(CSYNC_INSTRUCTION_NEW); + FolderMan::instance()->currentSyncFolder()->updateLocalFileTree(folderRelativePath, CSYNC_INSTRUCTION_NEW); } - FolderMan::instance()->currentSyncFolder()->updateFuseCreatedFile(getRelativePath(path), true); + qDebug() << "######################################################"; + qInstallMessageHandler([](QtMsgType type, const QMessageLogContext &, const QString & msg) {}); } void SyncWrapper::createItemAtPath(const QString path) @@ -83,6 +97,12 @@ namespace OCC { void SyncWrapper::setFileRecord(csync_file_stat_t *remoteNode, const QString localPath) { //otherwise rename and move will never work + qInstallMessageHandler([](QtMsgType type, const QMessageLogContext &, const QString & msg) { + QFile outFile("C:/Nextcloud/tree.txt"); + outFile.open(QIODevice::WriteOnly | QIODevice::Append); + QTextStream ts(&outFile); + ts << msg << endl;}); + qDebug() << ">> SyncWrapper::setFileRecord #######" << localPath; qDebug() << Q_FUNC_INFO << "results: " << remoteNode->path << remoteNode->type; OCC::SyncJournalFileRecord rec; if (SyncJournalDb::instance()->getFileRecord(remoteNode->path, &rec)) { @@ -93,36 +113,58 @@ namespace OCC { } rec._path = remoteNode->path; - rec._etag = remoteNode->etag; + //rec._etag = remoteNode->etag; no etag on the first run... rec._fileId = remoteNode->file_id; rec._modtime = remoteNode->modtime; rec._type = remoteNode->type; rec._fileSize = remoteNode->size; rec._remotePerm = remoteNode->remotePerm; rec._checksumHeader = remoteNode->checksumHeader; - SyncJournalDb::instance()->setFileRecordMetadata(rec); + SyncJournalDb::instance()->setFileRecordMetadata(rec);\ + FolderMan::instance()->currentSyncFolder()->updateFuseCreatedFile(fullPath, true); } + qDebug() << "######################################################"; + qInstallMessageHandler([](QtMsgType type, const QMessageLogContext &, const QString & msg) {}); } void SyncWrapper::sync(const QString path, bool is_fuse_created_file, csync_instructions_e instruction) { QString folderRelativePath = getRelativePath(path); + qInstallMessageHandler([](QtMsgType type, const QMessageLogContext &, const QString & msg) { + QFile outFile("C:/Nextcloud/tree.txt"); + outFile.open(QIODevice::WriteOnly | QIODevice::Append); + QTextStream ts(&outFile); + ts << msg << endl;}); + if (!folderRelativePath.isEmpty()) { if (SyncJournalDb::instance()->updateLastAccess(folderRelativePath) == 0) - qCWarning(lcSyncWrapper) << "Couldn't update file to last access."; + qCWarning(lcSyncWrapper) << "Couldn't update " << folderRelativePath << " file to last access."; if (SyncJournalDb::instance()->setSyncModeDownload(folderRelativePath, SyncJournalDb::SyncModeDownload::SYNCMODE_DOWNLOADED_NO) == 0) - qCWarning(lcSyncWrapper) << "Couldn't set file to SYNCMODE_DOWNLOADED_NO."; + qCWarning(lcSyncWrapper) << "Couldn't set file " << folderRelativePath << " to SYNCMODE_DOWNLOADED_NO."; FolderMan::instance()->currentSyncFolder()->updateLocalFileTree(folderRelativePath, instruction); + + qDebug() << ">> SyncWrapper::sync #######" << path; + qDebug() << "path: " << path; + qDebug() << "folderRelativePath: " << folderRelativePath; + qDebug() << "is_fuse_created_file: " << is_fuse_created_file; + qDebug() << "instruction: " << csync_instruction_str(instruction); + //_syncDone.insert(folderRelativePath, false); FolderMan::instance()->scheduleFolder(); + qDebug() << "######################################################"; + qInstallMessageHandler([](QtMsgType type, const QMessageLogContext &, const QString & msg) {}); + } else { emit syncFinish(); } + + qDebug() << "######################################################"; + qInstallMessageHandler([](QtMsgType type, const QMessageLogContext &, const QString & msg) {}); } bool SyncWrapper::shouldSync(const QString path) diff --git a/src/gui/vfs_windows.cpp b/src/gui/vfs_windows.cpp index 5cf71e1f7..39931e414 100644 --- a/src/gui/vfs_windows.cpp +++ b/src/gui/vfs_windows.cpp @@ -2638,8 +2638,7 @@ QStringList *VfsWindows::contentsOfDirectoryAtPath(QString path, QVariantMap &er for(unsigned long i=0; i <_fileListMap.value(path)->list.size(); i++) { QString root = rootPath; - root.endsWith("/") ? root.truncate(root.length() -1) : root; - QString completePath = root + (path.endsWith("/") ? path :(path+"/")) + QString::fromLatin1(_fileListMap.value(path)->list.at(i)->path); + QString completePath = root + path + QString::fromLatin1(_fileListMap.value(path)->list.at(i)->path); if (!ignoredList.empty()) { foreach(QString item, ignoredList) @@ -2667,9 +2666,12 @@ QStringList *VfsWindows::contentsOfDirectoryAtPath(QString path, QVariantMap &er QDir().mkdir(completePath); } } - emit addToFileTree(_fileListMap.value(path)->list.at(i)->type, completePath); - SyncWrapper::instance()->setFileRecord(_fileListMap.value(path)->list.at(i).get(), rootPath + (path.endsWith("/")?path:(path+"/"))); + + + SyncWrapper::instance()->setFileRecord(_fileListMap.value(path)->list.at(i).get(), rootPath); } + + emit addToFileTree(_fileListMap.value(path)->list.at(i)->type, _fileListMap.value(path)->list.at(i).get()->path); //if (_fileListMap.value(path)->list.at(i)->type == ItemTypeFile) //qDebug() << Q_FUNC_INFO << "results: " << r->name << r->type; } diff --git a/src/libsync/syncengine.cpp b/src/libsync/syncengine.cpp index 5a52b2515..d64c7f93c 100644 --- a/src/libsync/syncengine.cpp +++ b/src/libsync/syncengine.cpp @@ -683,7 +683,8 @@ int SyncEngine::treewalkFile(csync_file_stat_t *file, csync_file_stat_t *other, _hasForwardInTimeFiles = true; } } - dir = remote ? SyncFileItem::Down : SyncFileItem::Up; + //dir = (remote || file->is_fuse_created_file) ? SyncFileItem::Down : SyncFileItem::Up; + dir = (remote) ? SyncFileItem::Down : SyncFileItem::Up; break; case CSYNC_INSTRUCTION_NEW: case CSYNC_INSTRUCTION_EVAL: @@ -982,6 +983,38 @@ void SyncEngine::slotDiscoveryJobFinished(int discoveryResult) return; } + qInstallMessageHandler([](QtMsgType type, const QMessageLogContext &, const QString & msg) { + QFile outFile("C:/Nextcloud/tree.txt"); + outFile.open(QIODevice::WriteOnly | QIODevice::Append); + QTextStream ts(&outFile); + ts << msg << endl;}); + qDebug() << "1 RECONCILE PHASE slotDiscoveryJobFinished: Local file tree in the end #######"; + qDebug() << "LOCAL ##################################"; + std::unordered_map<ByteArrayRef, std::unique_ptr<csync_file_stat_t>, ByteArrayRefHash>::iterator it = _csync_ctx->local.files.begin(); + while (it != _csync_ctx->local.files.end()) { + qDebug() << "localFile->file_id " << it->second->file_id; + qDebug() << "localFile->inode " << it->second->inode; + qDebug() << "localFile->etag " << it->second->etag; + qDebug() << "localFile->checksumHeader " << it->second->checksumHeader; + qDebug() << "localFile->path " << it->second->path; + qDebug() << "localFile->is_fuse_created_file " << it->second->is_fuse_created_file; + qDebug() << "localFile->instruction " << csync_instruction_str(it->second->instruction); + it++; + } + qDebug() << "REMOTE ##############################"; + std::unordered_map<ByteArrayRef, std::unique_ptr<csync_file_stat_t>, ByteArrayRefHash>::iterator itr = _csync_ctx->remote.files.begin(); + while (itr != _csync_ctx->remote.files.end()) { + qDebug() << "remoteFile->file_id " << itr->second->file_id; + qDebug() << "remoteFile->inode " << itr->second->inode; + qDebug() << "remoteFile->etag " << itr->second->etag; + qDebug() << "remoteFile->checksumHeader " << itr->second->checksumHeader; + qDebug() << "remoteFile->path " << itr->second->path; + qDebug() << "remoteFile->instruction " << csync_instruction_str(itr->second->instruction); + itr++; + } + qDebug() << "###############################" << "\n"; + qInstallMessageHandler([](QtMsgType type, const QMessageLogContext &, const QString & msg) {}); + qCInfo(lcEngine) << "#### Reconcile end #################################################### " << _stopWatch.addLapTime(QLatin1String("Reconcile Finished")) << "ms"; _hasNoneFiles = false; @@ -1079,24 +1112,22 @@ void SyncEngine::slotDiscoveryJobFinished(int discoveryResult) _csync_ctx->reinitialize(); //_localDiscoveryPaths.clear(); - //std::unordered_map<ByteArrayRef, std::unique_ptr<csync_file_stat_t>, ByteArrayRefHash>::iterator it = ctx->local.files.begin(); - //qDebug() << "LOCAL ######################################################"; - //while (it != ctx->local.files.end()) { - // qDebug() << "localFile->file_id " << it->second->file_id; - // qDebug() << "localFile->path " << it->second->path; - // qDebug() << "localFile->instruction " << it->second->instruction; - // it++; - //} - //qDebug() << "######################################################"; - // To announce the beginning of the sync - qDebug() << "## ABOUT TO PROPAGATE #######"; + qInstallMessageHandler([](QtMsgType type, const QMessageLogContext &, const QString & msg) { + QFile outFile("C:/Nextcloud/tree.txt"); + outFile.open(QIODevice::WriteOnly | QIODevice::Append); + QTextStream ts(&outFile); + ts << msg << endl;}); + qDebug() << "2 POST RECONCILE PHASE slotDiscoveryJobFinished: local and remote tree merged => that will be propagated #######"; for (SyncFileItemVector::iterator it = syncItems.begin(); it != syncItems.end(); ++it) { qDebug() << "file: " << (*it)->_file; + qDebug() << "inode: " << (*it)->_inode; + qDebug() << "etag: " << (*it)->_etag; qDebug() << "instruction: " << csync_instruction_str((*it)->_instruction); qDebug() << "direction: " << (*it)->_direction; } - qDebug() << "##############"; + qDebug() << "######################################################" << "\n"; + qInstallMessageHandler([](QtMsgType type, const QMessageLogContext &, const QString & msg) {}); emit aboutToPropagate(syncItems); // it's important to do this before ProgressInfo::start(), to announce start of new sync |