-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Fix conflicts for offline uploads when uploading same file again #17590
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
70c2ed3
e928ac7
87746a9
96d9c54
4505acd
ad67ec8
0287f86
d75094f
b0b68ca
3cd0362
2092711
e82ac43
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 |
|---|---|---|
|
|
@@ -54,6 +54,7 @@ | |
| import com.owncloud.android.MainApp; | ||
| import com.owncloud.android.datamodel.e2e.v2.decrypted.DecryptedFolderMetadataFile; | ||
| import com.owncloud.android.db.ProviderMeta.ProviderTableMeta; | ||
| import com.owncloud.android.lib.common.OwnCloudClient; | ||
| import com.owncloud.android.lib.common.network.WebdavEntry; | ||
| import com.owncloud.android.lib.common.utils.Log_OC; | ||
| import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation; | ||
|
|
@@ -70,6 +71,7 @@ | |
| import com.owncloud.android.lib.resources.status.OCCapability; | ||
| import com.owncloud.android.lib.resources.tags.Tag; | ||
| import com.owncloud.android.operations.RemoteOperationFailedException; | ||
| import com.owncloud.android.operations.UploadFileOperation; | ||
| import com.owncloud.android.utils.FileStorageUtils; | ||
| import com.owncloud.android.utils.MimeType; | ||
| import com.owncloud.android.utils.MimeTypeUtil; | ||
|
|
@@ -200,7 +202,7 @@ public void addCreateFileOfflineOperation(String[] localPaths, String[] remotePa | |
| } | ||
|
|
||
| offlineOperationDao.insert(entity); | ||
| createPendingFile(remotePath, mimeType, createdAt, modificationTimestamp); | ||
| createPendingFile(remotePath, mimeType, createdAt, modificationTimestamp, localPath); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -230,8 +232,22 @@ public OfflineOperationEntity addCreateFolderOfflineOperation(String path, Strin | |
| return entity; | ||
| } | ||
|
|
||
| public void createPendingFile(String path, String mimeType, long createdAt, long modificationTimestamp) { | ||
| OCFile file = new OCFile(path); | ||
| public void createPendingFile( | ||
| String remotePath, | ||
| String mimeType, | ||
| long createdAt, | ||
| long modificationTimestamp, | ||
| String localPath | ||
| ) { | ||
| final OCFile existingFile = getFileByRemotePath(remotePath); | ||
| final File localFile = FileExtensionsKt.toFile(localPath); | ||
| if (FileExtensionsKt.isTheSameAs(existingFile, localFile)) { | ||
| // In case the same file was already uploaded, do not overwrite it to avoid triggering a conflict | ||
|
Collaborator
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. Just a tiny thing :) No need to have another comment since we have |
||
| Log_OC.i(TAG, "Creating pendingFile for an already uploaded file: keeping metadata"); | ||
| return; | ||
| } | ||
|
|
||
| OCFile file = new OCFile(remotePath); | ||
| file.setMimeType(mimeType); | ||
| file.setCreationTimestamp(createdAt); | ||
| file.setModificationTimestamp(modificationTimestamp); | ||
|
|
@@ -340,10 +356,7 @@ public void renameOfflineOperation(OCFile file, String newFolderName) { | |
| moveLocalFile(file, newPath, parentFolder.getDecryptedRemotePath()); | ||
| } | ||
|
|
||
| @SuppressLint("SimpleDateFormat") | ||
| public void keepOfflineOperationAndServerFile(OfflineOperationEntity entity, OCFile file) { | ||
| if (file == null) return; | ||
|
|
||
| public void keepOfflineOperationAndServerFile(OfflineOperationEntity entity, OCFile file, OwnCloudClient client) { | ||
| String oldFileName = entity.getFilename(); | ||
| if (oldFileName == null) return; | ||
|
|
||
|
|
@@ -353,13 +366,13 @@ public void keepOfflineOperationAndServerFile(OfflineOperationEntity entity, OCF | |
| OCFile parentFolder = getFileById(parentOCFileId); | ||
| if (parentFolder == null) return; | ||
|
|
||
| DateFormatPattern formatPattern = DateFormatPattern.FullDateWithHours; | ||
| String currentDateTime = DateExtensionsKt.currentDateRepresentation(new Date(), formatPattern); | ||
|
|
||
| String newFolderName = oldFileName + " - " + currentDateTime; | ||
| String newPath = parentFolder.getDecryptedRemotePath() + newFolderName + OCFile.PATH_SEPARATOR; | ||
| moveLocalFile(file, newPath, parentFolder.getDecryptedRemotePath()); | ||
| offlineOperationsRepository.updateNextOperations(entity); | ||
| final String newPath = UploadFileOperation.getNewAvailableRemotePath( | ||
|
Collaborator
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. Good improvement with
|
||
| client, | ||
| (entity.getPath() != null) ? entity.getPath() : file.getDecryptedRemotePath(), | ||
| List.of(oldFileName), | ||
| file.isEncrypted() | ||
| ); | ||
| offlineOperationsRepository.updateOperationForKeepBoth(entity, newPath); | ||
| } | ||
|
|
||
| @Nullable | ||
|
|
@@ -541,7 +554,7 @@ public List<OCFile> getFolderImagesAndVideos(OCFile folder, boolean onlyOnDevice | |
| } | ||
|
|
||
| public boolean saveFile(OCFile ocFile) { | ||
| Log_OC.d(TAG, "saving file: " + ocFile.getRemotePath()); | ||
| Log_OC.d(TAG, "saving file " + ocFile.getFileName() + " into " + ocFile.getRemotePath()); | ||
|
|
||
| boolean overridden = false; | ||
| final ContentValues cv = createContentValuesForFile(ocFile); | ||
|
|
||
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.