Discovery: Allow more HTTP error code to be treated as ignored dir
authorOlivier Goffart <ogoffart@woboq.com>
Wed, 13 Nov 2019 10:12:32 +0000 (11:12 +0100)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:59:03 +0000 (10:59 +0100)
The original code from csync was stopping at any error.
But we have been whitelisting soeme http error code one by one
to ignore the directory instead of aborting the sync.
However, as there are more requests to continue the sync in case
of error, just ignore most HTTP errors

Issue #7586

src/libsync/discovery.cpp

index 7d2b4e59933fc7035e719b713ba809b56c609fff..9ecb2a542a7171e2952228b7a7bb7e751e68bc33 100644 (file)
@@ -1415,34 +1415,24 @@ DiscoverySingleDirectoryJob *ProcessDirectoryJob::startAsyncServerQuery()
             if (_localQueryDone)
                 process();
         } else {
-            auto fatalError = [&] {
-                emit _discoveryData->fatalError(tr("Server replied with an error while reading directory '%1' : %2")
-                    .arg(_currentFolder._server, results.error().message));
-            };
-            auto ignoreOrFatal = [&] {
-                if (_dirItem) {
-                    _dirItem->_instruction = CSYNC_INSTRUCTION_IGNORE;
-                    _dirItem->_errorString = results.error().message;
-                    emit finished();
-                } else {
-                    // Fatal for the root job since it has no SyncFileItem
-                    fatalError();
-                }
-            };
-
             auto code = results.error().code;
             qCWarning(lcDisco) << "Server error in directory" << _currentFolder._server << code;
-            if (code == 403 || code == 404 || code == 500 || code == 503) {
+            if (_dirItem && code >= 403) {
+                // In case of an HTTP error, we ignore that directory
                 // 403 Forbidden can be sent by the server if the file firewall is active.
                 // A file or directory should be ignored and sync must continue. See #3490
                 // The server usually replies with the custom "503 Storage not available"
                 // if some path is temporarily unavailable. But in some cases a standard 503
                 // is returned too. Thus we can't distinguish the two and will treat any
                 // 503 as request to ignore the folder. See #3113 #2884.
-                // Similarly, the server might also return 404 or 500 in case of bugs. #7199
-                ignoreOrFatal();
+                // Similarly, the server might also return 404 or 50x in case of bugs. #7199 #7586
+                _dirItem->_instruction = CSYNC_INSTRUCTION_IGNORE;
+                _dirItem->_errorString = results.error().message;
+                emit finished();
             } else {
-                fatalError();
+                // Fatal for the root job since it has no SyncFileItem, or for the network errors
+                emit _discoveryData->fatalError(tr("Server replied with an error while reading directory '%1' : %2")
+                    .arg(_currentFolder._server, results.error().message));
             }
         }
     });