diff --git a/app/src/main/java/com/nextcloud/client/jobs/autoUpload/AutoUploadWorker.kt b/app/src/main/java/com/nextcloud/client/jobs/autoUpload/AutoUploadWorker.kt index b13ebabe7578..db0b09a2af7e 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/autoUpload/AutoUploadWorker.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/autoUpload/AutoUploadWorker.kt @@ -502,7 +502,7 @@ class AutoUploadWorker( val dateTime = formatter.parse(exifDate, pos) if (dateTime != null) { lastModificationTime = dateTime.time - Log_OC.w(TAG, "calculateLastModificationTime calculatedTime is: $lastModificationTime") + Log_OC.i(TAG, "calculateLastModificationTime calculatedTime is: $lastModificationTime") } else { Log_OC.w(TAG, "calculateLastModificationTime dateTime is empty") } diff --git a/app/src/main/java/com/nextcloud/client/jobs/utils/UploadErrorNotificationManager.kt b/app/src/main/java/com/nextcloud/client/jobs/utils/UploadErrorNotificationManager.kt index a9aa21d61f73..92c747faa22a 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/utils/UploadErrorNotificationManager.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/utils/UploadErrorNotificationManager.kt @@ -172,7 +172,7 @@ object UploadErrorNotificationManager { result.code == ResultCode.USER_CANCELLED || operation.isMissingPermissionThrown ) { - Log_OC.w(TAG, "operation is successful, cancelled or lack of storage permission") + Log_OC.i(TAG, "operation is successful, cancelled or lack of storage permission") return false } diff --git a/app/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java b/app/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java index 9a72022eef5a..b8b401627b65 100644 --- a/app/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java +++ b/app/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java @@ -193,16 +193,21 @@ private void updateUploadStatus(long id, UploadStatus status, UploadResult resul null ); - if (c != null) { - if (c.getCount() != SINGLE_RESULT) { - Log_OC.e(TAG, c.getCount() + " items for id=" + id - + " available in UploadDb. Expected 1. Failed to update upload db."); + try { + if (c != null) { + if (c.getCount() != SINGLE_RESULT) { + Log_OC.e(TAG, c.getCount() + " items for id=" + id + + " available in UploadDb. Expected 1. Failed to update upload db."); + } else { + updateUploadInternal(c, status, result, remotePath, localPath); + } } else { - updateUploadInternal(c, status, result, remotePath, localPath); + Log_OC.e(TAG, "Cursor is null"); + } + } finally { + if (c != null) { + c.close(); } - c.close(); - } else { - Log_OC.e(TAG, "Cursor is null"); } } @@ -302,9 +307,15 @@ OCUpload getUploadById(long id) { new String[]{Long.toString(id)}, "_id ASC"); - if (cursor != null) { - if (cursor.moveToFirst()) { - result = createOCUploadFromCursor(cursor); + try { + if (cursor != null) { + if (cursor.moveToFirst()) { + result = createOCUploadFromCursor(cursor); + } + } + } finally { + if (cursor != null) { + cursor.close(); } } Log_OC.d(TAG, "Retrieve job " + result + " for id " + id); @@ -414,8 +425,8 @@ private List getUploadPage(long limit, final long afterId, final boole pageSelectionArgs, sortOrder); - if (c != null) { - if (c.moveToFirst()) { + try { + if (c != null && c.moveToFirst()) { do { OCUpload upload = createOCUploadFromCursor(c); if (upload == null) { @@ -425,7 +436,10 @@ private List getUploadPage(long limit, final long afterId, final boole } } while (c.moveToNext() && !c.isAfterLast()); } - c.close(); + } finally { + if (c != null) { + c.close(); + } } return uploads; } diff --git a/app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java b/app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java index f13c73704962..3475b8614cd3 100644 --- a/app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java @@ -251,7 +251,7 @@ public UploadFileOperation(UploadsStorageManager uploadsStorageManager, this.user = user; mUpload = upload; if (file == null) { - Log_OC.w(TAG, "UploadFileOperation file is null, obtaining from upload"); + Log_OC.i(TAG, "UploadFileOperation file is null, obtaining from upload"); mFile = obtainNewOCFileToUpload( upload.getRemotePath(), upload.getLocalPath(), @@ -1232,7 +1232,31 @@ private RemoteOperationResult checkNameCollision(OCFile parentFile, switch (mNameCollisionPolicy) { case SKIP: Log_OC.d(TAG, "user choose to skip upload if same file exists"); - return new RemoteOperationResult<>(ResultCode.OK); + // For encrypted files, we can't easily compare content, so skip based on name only + // For non-encrypted files, check if it's actually the same file by content + if (!encrypted && mContext != null && user != null && mOriginalStoragePath != null) { + File localFile = new File(mOriginalStoragePath); + if (localFile.exists()) { + boolean isSameFile = FileUploadHelper.Companion.instance().isSameFileOnRemote( + user, localFile, mRemotePath, mContext); + if (isSameFile) { + Log_OC.d(TAG, "File is the same on remote, skipping upload"); + return new RemoteOperationResult<>(ResultCode.OK); + } else { + Log_OC.d(TAG, "File with same name exists but content is different, reporting conflict"); + // File exists but is different, return conflict so system can handle it + return new RemoteOperationResult(ResultCode.SYNC_CONFLICT); + } + } else { + Log_OC.w(TAG, "Local file does not exist, cannot compare content"); + // If local file doesn't exist, skip based on name only (old behavior) + return new RemoteOperationResult<>(ResultCode.OK); + } + } else { + // For encrypted files or when context/user/file path is unavailable, + // skip based on name only (preserve old behavior) + return new RemoteOperationResult<>(ResultCode.OK); + } case RENAME: mRemotePath = getNewAvailableRemotePath(client, mRemotePath, fileNames, encrypted); mWasRenamed = true; diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java b/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java index 969b29c8d349..52085cb4c4b7 100644 --- a/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java +++ b/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java @@ -624,30 +624,35 @@ private void handleContactResult(@NonNull Uri contactUri) { Cursor cursor = fileActivity.getContentResolver().query(contactUri, projection, null, null, null); - if (cursor != null) { - if (cursor.moveToFirst()) { - // The contact has only one email address, use it. - int columnIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.ADDRESS); - if (columnIndex != -1) { - // Use the email address as needed. - // email variable contains the selected contact's email address. - String email = cursor.getString(columnIndex); - binding.searchView.post(() -> { - binding.searchView.setQuery(email, false); - binding.searchView.requestFocus(); - }); + try { + if (cursor != null) { + if (cursor.moveToFirst()) { + // The contact has only one email address, use it. + int columnIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.ADDRESS); + if (columnIndex != -1) { + // Use the email address as needed. + // email variable contains the selected contact's email address. + String email = cursor.getString(columnIndex); + binding.searchView.post(() -> { + binding.searchView.setQuery(email, false); + binding.searchView.requestFocus(); + }); + } else { + DisplayUtils.showSnackMessage(binding.getRoot(), R.string.email_pick_failed); + Log_OC.e(FileDetailSharingFragment.class.getSimpleName(), "Failed to pick email address."); + } } else { DisplayUtils.showSnackMessage(binding.getRoot(), R.string.email_pick_failed); - Log_OC.e(FileDetailSharingFragment.class.getSimpleName(), "Failed to pick email address."); + Log_OC.e(FileDetailSharingFragment.class.getSimpleName(), "Failed to pick email address as no Email found."); } } else { DisplayUtils.showSnackMessage(binding.getRoot(), R.string.email_pick_failed); - Log_OC.e(FileDetailSharingFragment.class.getSimpleName(), "Failed to pick email address as no Email found."); + Log_OC.e(FileDetailSharingFragment.class.getSimpleName(), "Failed to pick email address as Cursor is null."); + } + } finally { + if (cursor != null) { + cursor.close(); } - cursor.close(); - } else { - DisplayUtils.showSnackMessage(binding.getRoot(), R.string.email_pick_failed); - Log_OC.e(FileDetailSharingFragment.class.getSimpleName(), "Failed to pick email address as Cursor is null."); } }