From c4299ebf683472cfe4753b0bf63277fd00d5072b Mon Sep 17 00:00:00 2001 From: alperozturk96 Date: Tue, 17 Feb 2026 15:26:59 +0100 Subject: [PATCH 1/5] check calls and dont set update size Signed-off-by: alperozturk96 --- .../operations/UploadFileOperation.java | 42 ++++++++++++++----- .../android/utils/FileStorageUtils.java | 5 +++ 2 files changed, 37 insertions(+), 10 deletions(-) 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 efbf642eb0c1..11be44cf5eae 100644 --- a/app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java @@ -436,27 +436,49 @@ protected RemoteOperationResult run(OwnCloudClient client) { mCancellationRequested.set(false); mUploadStarted.set(true); - updateSize(0); - String remoteParentPath = new File(getRemotePath()).getParent(); - remoteParentPath = remoteParentPath.endsWith(OCFile.PATH_SEPARATOR) ? remoteParentPath : remoteParentPath + OCFile.PATH_SEPARATOR; - remoteParentPath = AutoRename.INSTANCE.rename(remoteParentPath, getCapabilities()); + if (remoteParentPath == null) { + Log_OC.e(TAG, "remoteParentPath is null: " + getRemotePath()); + return new RemoteOperationResult<>(ResultCode.UNKNOWN_ERROR); + } + remoteParentPath = remoteParentPath.endsWith(OCFile.PATH_SEPARATOR) + ? remoteParentPath + : remoteParentPath + OCFile.PATH_SEPARATOR; + + final String renamedRemoteParentPath = AutoRename.INSTANCE.rename(remoteParentPath, getCapabilities()); + if (!remoteParentPath.equals(renamedRemoteParentPath)) { + Log_OC.w(TAG, "remoteParentPath was renamed: " + remoteParentPath + " → " + renamedRemoteParentPath); + } + remoteParentPath = renamedRemoteParentPath; OCFile parent = getStorageManager().getFileByPath(remoteParentPath); + Log_OC.d(TAG, "parent lookup for path: " + remoteParentPath + " → " + + (parent == null ? "not found in DB" : "found, id=" + parent.getFileId())); // in case of a fresh upload with subfolder, where parent does not exist yet if (parent == null && (mFolderUnlockToken == null || mFolderUnlockToken.isEmpty())) { - // try to create folder + Log_OC.d(TAG, "parent not in DB and no unlock token, attempting to grant folder existence: " + + remoteParentPath); final var result = grantFolderExistence(remoteParentPath, client); if (!result.isSuccess()) { + Log_OC.e(TAG, "grantFolderExistence failed for: " + remoteParentPath + ", code: " + + result.getCode() + ", message: " + result.getMessage()); return result; } parent = getStorageManager().getFileByPath(remoteParentPath); + if (parent == null) { + Log_OC.e(TAG, "parent still null after grantFolderExistence: " + remoteParentPath); + return new RemoteOperationResult<>(ResultCode.UNKNOWN_ERROR); + } + + Log_OC.d(TAG, "parent created and retrieved successfully: " + remoteParentPath + ", id=" + + parent.getFileId()); } if (parent == null) { + Log_OC.e(TAG, "parent is null, cannot proceed: " + remoteParentPath + "," + " unlock token: " + mFolderUnlockToken); return new RemoteOperationResult<>(false, "Parent folder not found", HttpStatus.SC_NOT_FOUND); } @@ -1366,9 +1388,9 @@ private OCCapability getCapabilities() { * @param pathToGrant Full remote path whose existence will be granted. * @return An {@link OCFile} instance corresponding to the folder where the file will be uploaded. */ - private RemoteOperationResult grantFolderExistence(String pathToGrant, OwnCloudClient client) { - RemoteOperation operation = new ExistenceCheckRemoteOperation(pathToGrant, false); - RemoteOperationResult result = operation.execute(client); + private RemoteOperationResult grantFolderExistence(String pathToGrant, OwnCloudClient client) { + var operation = new ExistenceCheckRemoteOperation(pathToGrant, false); + var result = operation.execute(client); if (!result.isSuccess() && result.getCode() == ResultCode.FILE_NOT_FOUND && mRemoteFolderToBeCreated) { SyncOperation syncOp = new CreateFolderOperation(pathToGrant, user, getContext(), getStorageManager()); result = syncOp.execute(client); @@ -1379,9 +1401,9 @@ private RemoteOperationResult grantFolderExistence(String pathToGrant, OwnCloudC parentDir = createLocalFolder(pathToGrant); } if (parentDir != null) { - result = new RemoteOperationResult(ResultCode.OK); + result = new RemoteOperationResult<>(ResultCode.OK); } else { - result = new RemoteOperationResult(ResultCode.CANNOT_CREATE_FILE); + result = new RemoteOperationResult<>(ResultCode.CANNOT_CREATE_FILE); } } return result; diff --git a/app/src/main/java/com/owncloud/android/utils/FileStorageUtils.java b/app/src/main/java/com/owncloud/android/utils/FileStorageUtils.java index b9988cbdba1f..c31e21a6a48d 100644 --- a/app/src/main/java/com/owncloud/android/utils/FileStorageUtils.java +++ b/app/src/main/java/com/owncloud/android/utils/FileStorageUtils.java @@ -588,6 +588,11 @@ public static void checkIfFileFinishedSaving(OCFile file) { * @return true if file itself or ancestor is encrypted */ public static boolean checkEncryptionStatus(OCFile file, FileDataStorageManager storageManager) { + if (file == null) { + Log_OC.e(TAG, "checkEncryptionStatus called with null file"); + return false; + } + if (file.isEncrypted()) { return true; } From 62a6444b6c86fec034e2c586c73e280772df769f Mon Sep 17 00:00:00 2001 From: alperozturk96 Date: Tue, 17 Feb 2026 16:15:00 +0100 Subject: [PATCH 2/5] add logs for file size determination Signed-off-by: alperozturk96 --- .../android/operations/UploadFileOperation.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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 11be44cf5eae..e7a9fa221c50 100644 --- a/app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java @@ -1097,8 +1097,16 @@ private RemoteOperationResult normalUpload(OwnCloudClient client) { long size; try { size = channel.size(); - } catch (IOException e) { - size = Files.size(filePath); + } catch (Exception e) { + Log_OC.e(TAG, "failed to determine file size from channel: ", e); + + try { + size = Files.size(filePath); + } catch (Exception exception) { + Log_OC.e(TAG, "failed to determine file size from nio.File: ", exception); + result = new RemoteOperationResult<>(ResultCode.FILE_NOT_FOUND); + return result; + } } updateSize(size); From bc01f34f0d90fdb15a0945298d00d1ec1f67cba0 Mon Sep 17 00:00:00 2001 From: alperozturk96 Date: Tue, 17 Feb 2026 16:15:12 +0100 Subject: [PATCH 3/5] add logs for file size determination Signed-off-by: alperozturk96 --- .../com/owncloud/android/operations/UploadFileOperation.java | 1 - 1 file changed, 1 deletion(-) 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 e7a9fa221c50..e8c44c6ff3a7 100644 --- a/app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java @@ -43,7 +43,6 @@ import com.owncloud.android.lib.common.network.OnDatatransferProgressListener; import com.owncloud.android.lib.common.network.ProgressiveDataTransfer; import com.owncloud.android.lib.common.operations.OperationCancelledException; -import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.lib.common.utils.Log_OC; From d5acc9fa1207a1ffe51a3cea86c855a1cca67d2e Mon Sep 17 00:00:00 2001 From: alperozturk96 Date: Wed, 18 Feb 2026 09:32:23 +0100 Subject: [PATCH 4/5] add logs revert update size Signed-off-by: alperozturk96 --- .../operations/UploadFileOperation.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) 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 e8c44c6ff3a7..1472c99a1b22 100644 --- a/app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java @@ -435,6 +435,9 @@ protected RemoteOperationResult run(OwnCloudClient client) { mCancellationRequested.set(false); mUploadStarted.set(true); + updateSize(0); + Log_OC.d(TAG, "file size set to 0KB before upload"); + String remoteParentPath = new File(getRemotePath()).getParent(); if (remoteParentPath == null) { Log_OC.e(TAG, "remoteParentPath is null: " + getRemotePath()); @@ -489,10 +492,10 @@ protected RemoteOperationResult run(OwnCloudClient client) { mFile.setEncrypted(encryptedAncestor); if (encryptedAncestor) { - Log_OC.d(TAG, "encrypted upload"); + Log_OC.d(TAG, "⬆️🔗" + "encrypted upload"); return encryptedUpload(client, parent); } else { - Log_OC.d(TAG, "normal upload"); + Log_OC.d(TAG, "⬆️" + "normal upload"); return normalUpload(client); } } @@ -1037,13 +1040,16 @@ private RemoteOperationResult normalUpload(OwnCloudClient client) { File expectedFile = null; try { + Log_OC.d(TAG, "checking conditions"); result = checkConditions(originalFile); if (result != null) { return result; } + Log_OC.d(TAG, "checking name collision"); final var collisionResult = checkNameCollision(null, client, null, false); if (collisionResult != null) { + Log_OC.e(TAG, "name collision detected"); result = collisionResult; return collisionResult; } @@ -1053,6 +1059,7 @@ private RemoteOperationResult normalUpload(OwnCloudClient client) { result = copyFile(originalFile, expectedPath); if (!result.isSuccess()) { + Log_OC.e(TAG, "file copying failed"); return result; } @@ -1108,6 +1115,7 @@ private RemoteOperationResult normalUpload(OwnCloudClient client) { } } updateSize(size); + Log_OC.d(TAG, "file size set to " + size); // decide whether chunked or not if (size > ChunkedFileUploadRemoteOperation.CHUNK_SIZE_MOBILE) { @@ -1123,6 +1131,8 @@ private RemoteOperationResult normalUpload(OwnCloudClient client) { mDisableRetries); } + Log_OC.d(TAG, "upload operation determined"); + /** * Adds the onTransferProgress in FileUploadWorker * {@link FileUploadWorker#onTransferProgress(long, long, long, String)()} @@ -1132,17 +1142,20 @@ private RemoteOperationResult normalUpload(OwnCloudClient client) { } if (mCancellationRequested.get()) { + Log_OC.e(TAG, "upload operation cancelled"); throw new OperationCancelledException(); } // execute if (result.isSuccess() && mUploadOperation != null) { + Log_OC.d(TAG, "upload operation completed"); result = mUploadOperation.execute(client); } // move local temporal file or original file to its corresponding // location in the Nextcloud local folder if (!result.isSuccess() && result.getHttpCode() == HttpStatus.SC_PRECONDITION_FAILED) { + Log_OC.e(TAG, "upload operation failed with SC_PRECONDITION_FAILED"); result = new RemoteOperationResult<>(ResultCode.SYNC_CONFLICT); } @@ -1198,7 +1211,7 @@ private void updateSize(long size) { } } - private void logResult(RemoteOperationResult result, String sourcePath, String targetPath) { + private void logResult(RemoteOperationResult result, String sourcePath, String targetPath) { if (result.isSuccess()) { Log_OC.i(TAG, "Upload of " + sourcePath + " to " + targetPath + ": " + result.getLogMessage()); } else { @@ -1231,7 +1244,7 @@ private RemoteOperationResult copyFile(File originalFile, String expectedPath) t throw new OperationCancelledException(); } - return new RemoteOperationResult(ResultCode.OK); + return new RemoteOperationResult<>(ResultCode.OK); } @CheckResult From 1254e709ac48a6626a5d24197a8febe8eb6d2d74 Mon Sep 17 00:00:00 2001 From: alperozturk96 Date: Wed, 18 Feb 2026 09:35:57 +0100 Subject: [PATCH 5/5] add logs revert update size Signed-off-by: alperozturk96 --- .../com/owncloud/android/operations/UploadFileOperation.java | 1 + 1 file changed, 1 insertion(+) 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 1472c99a1b22..ec5aa8f563c0 100644 --- a/app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java @@ -414,6 +414,7 @@ public boolean isMissingPermissionThrown() { @Override @SuppressWarnings("PMD.AvoidDuplicateLiterals") protected RemoteOperationResult run(OwnCloudClient client) { + Log_OC.d(TAG, "------- Upload File Operation Started -------"); if (TextUtils.isEmpty(getStoragePath())) { Log_OC.e(TAG, "Upload cancelled for " + getStoragePath() + ": file path is null or empty."); return new RemoteOperationResult<>(new UploadFileException.EmptyOrNullFilePath());