only use if match (etag) header in upload if remote file exist
Description
When eDrive try to upload a small file (file size < 3MB). If remote file is missing on the cloud, the upload fails and return HTTP 412 error.
This MR prevent this by checking if file still exist on server first. If the remote file is missing, the "if-match" header is not used to upload the file
Screenshots
Technical details
https://gitlab.e.foundation/e/os/backlog/-/issues/919#note_379313
Tests
- Let eDrive sync many files
- remove one file on the cloud
- Before next periodic scan, update the local file in order to generate a new upload
- the file should be uploaded again
No HTTP 412 should be seen
Expected result example:
BEFORE
04-24 16:59:27.252 3106 3282 D FileEventListener: handleFileCloseWrite( /storage/emulated/0/Documents/test412.txt )
04-24 16:59:27.257 3106 3282 D SyncedFileStateDAO: Sending a SyncRequest for test412.txt
04-24 16:59:27.258 3106 3282 I SynchronizationService: startAllThreads
04-24 16:59:27.259 3106 3282 V CommonUtils: haveNetworkConnection()
04-24 16:59:27.263 3106 3282 V UploadFileOperation: starts test412.txt UPLOAD on thread 0
04-24 16:59:27.264 3106 3282 V CommonUtils: haveNetworkConnection()
04-24 16:59:27.271 3106 11437 V DavClientProvider: getNcClientInstance()
04-24 16:59:28.524 3106 11437 D OwnCloudClient #0: REQUEST MKCOL /remote.php/dav/files/vince.bourgmayer@e.email/Documents/
04-24 16:59:29.583 3106 11437 D CreateFolderRemoteOperation: Create directory /Documents/: Operation finished with HTTP status code -1 (fail)
04-24 16:59:29.593 3106 11437 D OwnCloudClient #0: REQUEST PUT /remote.php/dav/files/vince.bourgmayer@e.email/Documents/test412.txt
04-24 16:59:30.459 3106 11437 D RemoteOperationResult: RemoteOperationResult has processed UNHANDLED_HTTP_CODE: 412 Precondition failed
04-24 16:59:30.460 3106 11437 D UploadFileOperation: Upload for test412.txt failed : UNHANDLED_HTTP_CODE
04-24 16:59:30.461 3106 11437 D DbHelper: manageSyncedFileStateDB( test412.txt, UPDATE )
04-24 16:59:30.468 3106 3439 I SynchronizationService: onRemoteOperationFinish()
After
4-24 17:06:03.428 3122 3396 D FileEventListener: handleFileCloseWrite( /storage/emulated/0/Documents/join.txt )
04-24 17:06:03.435 3122 3396 D SyncedFileStateDAO: Sending a SyncRequest for join.txt
04-24 17:06:03.435 3122 3396 I SynchronizationService: startAllThreads
04-24 17:06:03.436 3122 3396 V CommonUtils: haveNetworkConnection()
04-24 17:06:03.440 3122 3396 V UploadFileOperation: starts join.txt UPLOAD on thread 0
04-24 17:06:03.442 3122 3396 V CommonUtils: haveNetworkConnection()
04-24 17:06:03.445 3122 5443 V DavClientProvider: getNcClientInstance()
04-24 17:06:04.415 3122 5443 D OwnCloudClient #0: REQUEST MKCOL /remote.php/dav/files/vince.bourgmayer@e.email/Documents/
04-24 17:06:05.370 3122 5443 D CreateFolderRemoteOperation: Create directory /Documents/: Operation finished with HTTP status code -1 (fail)
04-24 17:06:05.380 3122 5443 D OwnCloudClient #0: REQUEST HEAD /remote.php/dav/files/vince.bourgmayer@e.email/Documents/join.txt
04-24 17:06:06.186 3122 5443 D ExistenceCheckRemoteOperation: Existence check for https://murena.io/remote.php/dav/files/vince.bourgmayer@e.email/Documents/join.txt targeting for existence finished with HTTP status 404(FAIL)
04-24 17:06:06.191 3122 5443 D OwnCloudClient #0: REQUEST PUT /remote.php/dav/files/vince.bourgmayer@e.email/Documents/join.txt
04-24 17:06:08.460 3122 5443 D DbHelper: manageSyncedFileStateDB( join.txt, UPDATE )
04-24 17:06:08.471 3122 3469 I SynchronizationService: onRemoteOperationFinish()
04-24 17:06:08.472 3122 3469 D SynchronizationService: UploadFileOperation Succeed
04-24 17:06:08.474 3122 3469 V CommonUtils: haveNetworkConnection()
Issues
https://gitlab.e.foundation/e/os/backlog/-/issues/919
10 commandments of code reviews
Edited by Vincent Bourgmayer