-
Notifications
You must be signed in to change notification settings - Fork 935
fix(upload): skip locked files during upload to avoid errors #9810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
efb4a96
763393f
0e9013e
ce16030
fa1fd11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,3 +1,3 @@ | ||||||
| /* | ||||||
| * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors | ||||||
| * SPDX-FileCopyrightText: 2018 ownCloud GmbH | ||||||
|
|
@@ -28,10 +28,10 @@ | |||||
|
|
||||||
| namespace | ||||||
| { | ||||||
| constexpr const char *editorNamesForDelayedUpload[] = {"PowerPDF"}; | ||||||
|
Check warning on line 31 in src/libsync/discovery.cpp
|
||||||
| constexpr const char *fileExtensionsToCheckIfOpenForSigning[] = {".pdf"}; | ||||||
|
Check warning on line 32 in src/libsync/discovery.cpp
|
||||||
| constexpr auto delayIntervalForSyncRetryForOpenedForSigningFilesSeconds = 60; | ||||||
| constexpr auto delayIntervalForSyncRetryForFilesExceedQuotaSeconds = 60; | ||||||
|
Check warning on line 34 in src/libsync/discovery.cpp
|
||||||
| } | ||||||
|
|
||||||
| namespace OCC { | ||||||
|
|
@@ -281,7 +281,7 @@ | |||||
| #if defined Q_OS_WINDOWS | ||||||
| if (hasLeadingOrTrailingSpaces && leadingAndTrailingSpacesFilesAllowed) { | ||||||
| #else | ||||||
| if (hasLeadingOrTrailingSpaces && (wasSyncedAlready || leadingAndTrailingSpacesFilesAllowed)) { | ||||||
|
Check warning on line 284 in src/libsync/discovery.cpp
|
||||||
| #endif | ||||||
| excluded = CSYNC_NOT_EXCLUDED; | ||||||
| } | ||||||
|
|
@@ -354,6 +354,14 @@ | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| if (excluded == CSYNC_NOT_EXCLUDED && OCC::FileSystem::isFileLocked(_discoveryData->_localDir + path, OCC::FileSystem::LockMode::SharedRead) && | ||||||
| (!entries.dbEntry.isValid() || !entries.serverEntry.isValid() || entries.serverEntry.etag == entries.dbEntry._etag)) { | ||||||
| qCInfo(lcDisco) << _discoveryData->_localDir + path << "is locked" << "exluding it from sync"; | ||||||
| excluded = CSYNC_FILE_LOCKED_SILENTLY_EXCLUDED; | ||||||
|
|
||||||
| emit _discoveryData->seenLockedFile(_discoveryData->_localDir + path); | ||||||
| } | ||||||
|
|
||||||
| if (excluded == CSYNC_NOT_EXCLUDED && !entries.localEntry.isSymLink) { | ||||||
| return false; | ||||||
| } else if (excluded == CSYNC_FILE_SILENTLY_EXCLUDED || excluded == CSYNC_FILE_EXCLUDE_AND_REMOVE) { | ||||||
|
|
@@ -384,6 +392,9 @@ | |||||
| case CSYNC_FILE_EXCLUDE_AND_REMOVE: | ||||||
| qCFatal(lcDisco) << "These were handled earlier"; | ||||||
| break; | ||||||
| case CSYNC_FILE_LOCKED_SILENTLY_EXCLUDED: | ||||||
| item->_errorString = tr("File is locked exluding it from sync."); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| break; | ||||||
| case CSYNC_FILE_EXCLUDE_LIST: | ||||||
| item->_errorString = tr("File is listed on the ignore list."); | ||||||
| break; | ||||||
|
|
@@ -415,7 +426,7 @@ | |||||
| } | ||||||
| item->_status = SyncFileItem::FileNameInvalid; | ||||||
| break; | ||||||
| case CSYNC_FILE_EXCLUDE_TRAILING_SPACE: | ||||||
|
Check warning on line 429 in src/libsync/discovery.cpp
|
||||||
| item->_errorString = tr("Filename contains trailing spaces."); | ||||||
| item->_status = SyncFileItem::FileNameInvalid; | ||||||
| if (isLocal && !maybeRenameForWindowsCompatibility(_discoveryData->_localDir + item->_file, excluded)) { | ||||||
|
|
@@ -457,7 +468,7 @@ | |||||
| case CSYNC_FILE_EXCLUDE_CANNOT_ENCODE: | ||||||
| item->_errorString = tr("The filename cannot be encoded on your file system."); | ||||||
| break; | ||||||
| case CSYNC_FILE_EXCLUDE_SERVER_BLACKLISTED: | ||||||
|
Check warning on line 471 in src/libsync/discovery.cpp
|
||||||
| const auto errorString = tr("The filename is blacklisted on the server."); | ||||||
| QString reasonString; | ||||||
| if (hasForbiddenFilename) { | ||||||
|
|
@@ -683,7 +694,7 @@ | |||||
| _pendingAsyncJobs++; | ||||||
| _discoveryData->checkSelectiveSyncNewFolder(path._server, | ||||||
| serverEntry.remotePerm, | ||||||
| [=, this](bool result) { | ||||||
|
Check failure on line 697 in src/libsync/discovery.cpp
|
||||||
| --_pendingAsyncJobs; | ||||||
| if (!result) { | ||||||
| processFileAnalyzeLocalInfo(item, path, localEntry, serverEntry, dbEntry, _queryServer); | ||||||
|
|
@@ -1050,7 +1061,7 @@ | |||||
| // we need to make a request to the server to know that the original file is deleted on the server | ||||||
| _pendingAsyncJobs++; | ||||||
| const auto job = new RequestEtagJob(_discoveryData->_account, _discoveryData->_remoteFolder + originalPath, this); | ||||||
| connect(job, &RequestEtagJob::finishedWithResult, this, [=, this](const HttpResult<QByteArray> &etag) mutable { | ||||||
|
Check failure on line 1064 in src/libsync/discovery.cpp
|
||||||
| _pendingAsyncJobs--; | ||||||
| QTimer::singleShot(0, _discoveryData, &DiscoveryPhase::scheduleMoreJobs); | ||||||
| if (etag || etag.error().code != 404 || | ||||||
|
|
@@ -1599,7 +1610,7 @@ | |||||
| const auto serverHasMountRootProperty = _discoveryData->_account->serverHasMountRootProperty(); | ||||||
| const auto isExternalStorage = base._remotePerm.hasPermission(RemotePermissions::IsMounted) && base.isDirectory(); | ||||||
| const auto movePerms = checkMovePermissions(base._remotePerm, originalPath, item->isDirectory()); | ||||||
| if (!movePerms.sourceOk || !movePerms.destinationOk || (serverHasMountRootProperty && isExternalStorage) || isE2eeMoveOnlineOnlyItemWithCfApi) { | ||||||
|
Check warning on line 1613 in src/libsync/discovery.cpp
|
||||||
| qCInfo(lcDisco) << "Move without permission to rename base file, " | ||||||
| << "source:" << movePerms.sourceOk | ||||||
| << ", target:" << movePerms.destinationOk | ||||||
|
|
@@ -1684,7 +1695,7 @@ | |||||
| if (base.isVirtualFile() && isVfsWithSuffix()) | ||||||
| chopVirtualFileSuffix(serverOriginalPath); | ||||||
| auto job = new RequestEtagJob(_discoveryData->_account, serverOriginalPath, this); | ||||||
| connect(job, &RequestEtagJob::finishedWithResult, this, [=, this](const HttpResult<QByteArray> &etag) mutable { | ||||||
|
Check failure on line 1698 in src/libsync/discovery.cpp
|
||||||
|
|
||||||
|
|
||||||
| if (!etag || (etag.get() != base._etag && !item->isDirectory()) || _discoveryData->isRenamed(originalPath) | ||||||
|
|
@@ -1730,7 +1741,7 @@ | |||||
| // If there's no content hash, use heuristics | ||||||
| if (serverEntry.checksumHeader.isEmpty()) { | ||||||
| // If the size or mtime is different, it's definitely a conflict. | ||||||
| bool isConflict = (serverEntry.size != localEntry.size) || (serverEntry.modtime != localEntry.modtime) || (dbEntry.isValid() && dbEntry._modtime != localEntry.modtime && serverEntry.modtime == localEntry.modtime); | ||||||
|
Check warning on line 1744 in src/libsync/discovery.cpp
|
||||||
|
|
||||||
| // It could be a conflict even if size and mtime match! | ||||||
| // | ||||||
|
|
@@ -2107,7 +2118,7 @@ | |||||
| } | ||||||
|
|
||||||
| const auto isMatchingFileExtension = std::find_if(std::cbegin(fileExtensionsToCheckIfOpenForSigning), std::cend(fileExtensionsToCheckIfOpenForSigning), | ||||||
| [path](const auto &matchingExtension) { | ||||||
|
Check warning on line 2121 in src/libsync/discovery.cpp
|
||||||
| return path._local.endsWith(matchingExtension, Qt::CaseInsensitive); | ||||||
| }) != std::cend(fileExtensionsToCheckIfOpenForSigning); | ||||||
|
|
||||||
|
|
@@ -2120,7 +2131,7 @@ | |||||
|
|
||||||
| for (const auto &detectedEditorName : editorsKeepingFileBusy) { | ||||||
| const auto isMatchingEditorFound = std::find_if(std::cbegin(editorNamesForDelayedUpload), std::cend(editorNamesForDelayedUpload), | ||||||
| [detectedEditorName](const auto &matchingEditorName) { | ||||||
|
Check warning on line 2134 in src/libsync/discovery.cpp
|
||||||
| return detectedEditorName.processName.startsWith(matchingEditorName, Qt::CaseInsensitive); | ||||||
| }) != std::cend(editorNamesForDelayedUpload); | ||||||
| if (isMatchingEditorFound) { | ||||||
|
|
@@ -2354,7 +2365,7 @@ | |||||
| void ProcessDirectoryJob::startAsyncLocalQuery() | ||||||
| { | ||||||
| QString localPath = _discoveryData->_localDir + _currentFolder._local; | ||||||
| auto localJob = new DiscoverySingleLocalDirectoryJob(_discoveryData->_account, localPath, _discoveryData->_syncOptions._vfs.data(), _discoveryData->_fileSystemReliablePermissions); | ||||||
|
Check warning on line 2368 in src/libsync/discovery.cpp
|
||||||
|
|
||||||
| _discoveryData->_currentlyActiveJobs++; | ||||||
| _pendingAsyncJobs++; | ||||||
|
|
@@ -2443,19 +2454,20 @@ | |||||
| } | ||||||
|
|
||||||
| bool ProcessDirectoryJob::maybeRenameForWindowsCompatibility(const QString &absoluteFileName, | ||||||
| CSYNC_EXCLUDE_TYPE excludeReason) | ||||||
|
Check warning on line 2457 in src/libsync/discovery.cpp
|
||||||
| { | ||||||
| auto result = true; | ||||||
|
|
||||||
| const auto leadingAndTrailingSpacesFilesAllowed = !_discoveryData->_shouldEnforceWindowsFileNameCompatibility || _discoveryData->_leadingAndTrailingSpacesFilesAllowed.contains(absoluteFileName); | ||||||
| if (leadingAndTrailingSpacesFilesAllowed) { | ||||||
|
Check warning on line 2462 in src/libsync/discovery.cpp
|
||||||
| return result; | ||||||
| } | ||||||
|
|
||||||
| const auto fileInfo = QFileInfo{absoluteFileName}; | ||||||
| switch (excludeReason) | ||||||
|
Check failure on line 2467 in src/libsync/discovery.cpp
|
||||||
| { | ||||||
| case CSYNC_NOT_EXCLUDED: | ||||||
| case CSYNC_FILE_LOCKED_SILENTLY_EXCLUDED: | ||||||
| case CSYNC_FILE_EXCLUDE_CASE_CLASH_CONFLICT: | ||||||
| case CSYNC_FILE_EXCLUDE_AND_REMOVE: | ||||||
| case CSYNC_FILE_EXCLUDE_CANNOT_ENCODE: | ||||||
|
|
@@ -2470,10 +2482,10 @@ | |||||
| break; | ||||||
| case CSYNC_FILE_EXCLUDE_LEADING_AND_TRAILING_SPACE: | ||||||
| case CSYNC_FILE_EXCLUDE_LEADING_SPACE: | ||||||
| case CSYNC_FILE_EXCLUDE_TRAILING_SPACE: | ||||||
|
Check warning on line 2485 in src/libsync/discovery.cpp
|
||||||
| { | ||||||
| const auto removeTrailingSpaces = [] (QString string) -> QString { | ||||||
| for (int n = string.size() - 1; n >= 0; -- n) { | ||||||
|
Check warning on line 2488 in src/libsync/discovery.cpp
|
||||||
| if (!string.at(n).isSpace()) { | ||||||
| string.truncate(n + 1); | ||||||
| break; | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,7 +55,6 @@ | |
| // For failures, we want to add the file to the list so the next sync | ||
| // will be able to retry it. | ||
| if (item->_status == SyncFileItem::Success | ||
| || item->_status == SyncFileItem::FileIgnored | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why was this removed? |
||
| || item->_status == SyncFileItem::Restoration | ||
| || item->_status == SyncFileItem::Conflict | ||
| || (item->_status == SyncFileItem::NoStatus | ||
|
|
@@ -66,7 +65,7 @@ | |
| if (!item->_renameTarget.isEmpty() && _previousLocalDiscoveryPaths.erase(item->_renameTarget.toUtf8())) | ||
| qCDebug(lcLocalDiscoveryTracker) << "wiped successful item" << item->_renameTarget; | ||
| } else { | ||
| _localDiscoveryPaths.insert(item->_file.toUtf8()); | ||
|
Check warning on line 68 in src/libsync/localdiscoverytracker.cpp
|
||
| qCWarning(lcLocalDiscoveryTracker) << "inserted error item" << item->_file; | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
CSYNC_EXCLUDE_TYPEenum now has a more specific enum value for this case: