-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
BugFix - Stop Re-Upload Same File Due To File Extension #15253
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
60df73e
af6e5db
4d3a8db
23cf035
5c2aa00
f9f26ab
d22acba
0a7c139
14b1415
10ab58b
3b6f42e
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 |
|---|---|---|
|
|
@@ -10,27 +10,77 @@ package com.nextcloud.client.jobs.operation | |
| import android.content.Context | ||
| import com.nextcloud.client.account.User | ||
| import com.nextcloud.utils.extensions.getErrorMessage | ||
| import com.nextcloud.utils.extensions.toFile | ||
| import com.owncloud.android.datamodel.FileDataStorageManager | ||
| import com.owncloud.android.datamodel.OCFile | ||
| import com.owncloud.android.db.OCUpload | ||
| import com.owncloud.android.lib.common.OwnCloudClient | ||
| import com.owncloud.android.lib.common.utils.Log_OC | ||
| import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation | ||
| import com.owncloud.android.lib.resources.files.ReadFolderRemoteOperation | ||
| import com.owncloud.android.lib.resources.files.model.RemoteFile | ||
| import com.owncloud.android.operations.RemoveFileOperation | ||
| import com.owncloud.android.utils.FileUtil | ||
| import com.owncloud.android.utils.MimeTypeUtil | ||
| import kotlinx.coroutines.Dispatchers | ||
| import kotlinx.coroutines.async | ||
| import kotlinx.coroutines.withContext | ||
|
|
||
| class FileOperationHelper( | ||
| private val user: User, | ||
| private val context: Context, | ||
| private val fileDataStorageManager: FileDataStorageManager | ||
| ) { | ||
| class FileOperationHelper(private val user: User, private val context: Context) { | ||
| companion object { | ||
| private val TAG = FileOperationHelper::class.java.simpleName | ||
| } | ||
|
|
||
| /** | ||
| * Checks if a file with the same remote path (case-insensitive) and unchanged content | ||
| * already exists in local storage by considering both lowercase and uppercase variants | ||
| * of the file extension. | ||
| * | ||
| * ### Example: | ||
| * ``` | ||
| * On the server, 0001.WEBP exists and the user tries to upload the same file | ||
| * with the lowercased version 0001.webp — in that case, this will return true. | ||
| * ``` | ||
| */ | ||
| fun isSameRemoteFileAlreadyPresent(upload: OCUpload, storageManager: FileDataStorageManager): Boolean { | ||
| val (lc, uc) = FileUtil.getRemotePathVariants(upload.remotePath) | ||
|
|
||
| val remoteFile = storageManager.run { | ||
| getFileByDecryptedRemotePath(lc) ?: getFileByDecryptedRemotePath(uc) | ||
| } | ||
|
|
||
| if (upload.toFile()?.length() == remoteFile?.fileLength) { | ||
|
Collaborator
Author
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. I need to compare a local file intended for upload with an existing remote file to determine if they are exactly the same. While file size can be used as a basic check, I’m looking for a more reliable method. Using At this point, I have a Any suggestions for a more robust comparison method beyond file size? |
||
| Log_OC.w(TAG, "Same file already exists due to lowercase/uppercase extension") | ||
| return true | ||
| } | ||
|
|
||
| return false | ||
| } | ||
|
|
||
| @Suppress("DEPRECATION") | ||
| fun getRemoteFile(remotePath: String, client: OwnCloudClient): RemoteFile? { | ||
| val mimeType = MimeTypeUtil.getMimeTypeFromPath(remotePath) | ||
| val isFolder = MimeTypeUtil.isFolder(mimeType) | ||
| val result = if (isFolder) { | ||
| ReadFolderRemoteOperation(remotePath).execute(client) | ||
| } else { | ||
| ReadFileRemoteOperation(remotePath).execute(client) | ||
| } | ||
|
|
||
| return if (result.isSuccess) { | ||
| result.data[0] as? RemoteFile | ||
| } else { | ||
| null | ||
| } | ||
| } | ||
|
|
||
| fun isFileChanged(remoteFile: RemoteFile?, ocFile: OCFile?): Boolean = | ||
| (remoteFile != null && ocFile != null && remoteFile.etag != ocFile.etagOnServer) | ||
|
|
||
| @Suppress("TooGenericExceptionCaught", "Deprecation") | ||
| suspend fun removeFile( | ||
| file: OCFile, | ||
| storageManager: FileDataStorageManager, | ||
| onlyLocalCopy: Boolean, | ||
| inBackground: Boolean, | ||
| client: OwnCloudClient | ||
|
|
@@ -44,7 +94,7 @@ class FileOperationHelper( | |
| user, | ||
| inBackground, | ||
| context, | ||
| fileDataStorageManager | ||
| storageManager | ||
| ) | ||
| } | ||
| val operationResult = operation.await() | ||
|
|
||
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.
OfflineOperationWorkerwas updated to use the logic inFileUtilto prevent code duplication and unify similar functionality.