diff options
author | alex-z <blackslayer4@gmail.com> | 2022-02-16 14:14:47 +0300 |
---|---|---|
committer | alex-z <blackslayer4@gmail.com> | 2022-03-09 11:54:39 +0300 |
commit | 01eb050cd85457e7e222bea9cad55e22af9426eb (patch) | |
tree | 63f2baaddf470ece5deaeda930b6136fe91a8445 /src/libsync/discovery.cpp | |
parent | c347b4713ac799dd7a4f1912b2429533df4a2311 (diff) |
Do not remove files from a Group folder and its nested folders whe it is renamed or removed while not allowed.bugfix/group-folder-files-erased-when-rename-or-delete-folder
Signed-off-by: alex-z <blackslayer4@gmail.com>
Diffstat (limited to 'src/libsync/discovery.cpp')
-rw-r--r-- | src/libsync/discovery.cpp | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/src/libsync/discovery.cpp b/src/libsync/discovery.cpp index 80d57201b..c9a3b1d53 100644 --- a/src/libsync/discovery.cpp +++ b/src/libsync/discovery.cpp @@ -1295,8 +1295,11 @@ void ProcessDirectoryJob::processFileAnalyzeLocalInfo( chopVirtualFileSuffix(serverOriginalPath); auto job = new RequestEtagJob(_discoveryData->_account, serverOriginalPath, this); connect(job, &RequestEtagJob::finishedWithResult, this, [=](const HttpResult<QByteArray> &etag) mutable { - if (!etag || (etag.get() != base._etag && !item->isDirectory()) || _discoveryData->isRenamed(originalPath)) { - qCInfo(lcDisco) << "Can't rename because the etag has changed or the directory is gone" << originalPath; + + + if (!etag || (etag.get() != base._etag && !item->isDirectory()) || _discoveryData->isRenamed(originalPath) + || (isAnyParentBeingRestored(originalPath) && !isRename(originalPath))) { + qCInfo(lcDisco) << "Can't rename because the etag has changed or the directory is gone or we are restoring one of the file's parents." << originalPath; // Can't be a rename, leave it as a new. postProcessLocalNew(); } else { @@ -1436,7 +1439,7 @@ void ProcessDirectoryJob::processFileFinalize( job->setInsideEncryptedTree(isInsideEncryptedTree() || item->_isEncrypted); if (removed) { job->setParent(_discoveryData); - _discoveryData->_queuedDeletedDirectories[path._original] = job; + _discoveryData->enqueueDirectoryToDelete(path._original, job); } else { connect(job, &ProcessDirectoryJob::finished, this, &ProcessDirectoryJob::subJobFinished); _queuedJobs.push_back(job); @@ -1550,7 +1553,8 @@ bool ProcessDirectoryJob::checkPermissions(const OCC::SyncFileItemPtr &item) // No permissions set return true; } - if (!perms.hasPermission(RemotePermissions::CanDelete)) { + if (!perms.hasPermission(RemotePermissions::CanDelete) || isAnyParentBeingRestored(item->_file)) + { item->_instruction = CSYNC_INSTRUCTION_NEW; item->_direction = SyncFileItem::Down; item->_isRestoration = true; @@ -1566,6 +1570,35 @@ bool ProcessDirectoryJob::checkPermissions(const OCC::SyncFileItemPtr &item) return true; } +bool ProcessDirectoryJob::isAnyParentBeingRestored(const QString &file) const +{ + for (const auto &directoryNameToRestore : _discoveryData->_directoryNamesToRestoreOnPropagation) { + if (file.startsWith(QString(directoryNameToRestore + QLatin1Char('/')))) { + qCWarning(lcDisco) << "File" << file << " is within the tree that's being restored" << directoryNameToRestore; + return true; + } + } + return false; +} + +bool ProcessDirectoryJob::isRename(const QString &originalPath) const +{ + return (originalPath.startsWith(_currentFolder._original) + && originalPath.lastIndexOf('/') == _currentFolder._original.size()); + + /* TODO: This was needed at some point to cover an edge case which I am no longer to reproduce and it might no longer be the case. + * Still, leaving this here just in case the edge case is caught at some point in future. + * + OCC::SyncJournalFileRecord base; + // are we allowed to rename? + if (!_discoveryData || !_discoveryData->_statedb || !_discoveryData->_statedb->getFileRecord(originalPath, &base)) { + return false; + } + qCWarning(lcDisco) << "isRename from" << originalPath << " to" << targetPath << " :" + << base._remotePerm.hasPermission(RemotePermissions::CanRename); + return base._remotePerm.hasPermission(RemotePermissions::CanRename); + */ +} auto ProcessDirectoryJob::checkMovePermissions(RemotePermissions srcPerm, const QString &srcPath, bool isDirectory) |