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 d525f37de441..54fce4a3e744 100644 --- a/app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java @@ -55,6 +55,7 @@ import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation; import com.owncloud.android.lib.resources.files.UploadFileRemoteOperation; import com.owncloud.android.lib.resources.files.model.RemoteFile; +import com.owncloud.android.lib.resources.status.NextcloudVersion; import com.owncloud.android.lib.resources.status.OCCapability; import com.owncloud.android.operations.common.SyncOperation; import com.owncloud.android.operations.e2e.E2EClientData; @@ -472,37 +473,42 @@ protected RemoteOperationResult run(OwnCloudClient client) { Log_OC.d(TAG, "parent lookup for path: " + remoteParentPath + " → " + (parent == null ? "not found in DB" : "found, id=" + parent.getFileId())); - final boolean isResumingEncryptedUpload = (mFolderUnlockToken != null && !mFolderUnlockToken.isEmpty()); - if (!isResumingEncryptedUpload && (parent == null || mRemoteFolderToBeCreated)) { - Log_OC.d(TAG, "verifying remote parent folder exists: " + 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; + // Create folders only for Nextcloud < 32; 32+ handles this automatically. + if (getCapabilities().getVersion().isOlderThan(NextcloudVersion.nextcloud_32)) { + final boolean isResumingEncryptedUpload = (mFolderUnlockToken != null && !mFolderUnlockToken.isEmpty()); + if (!isResumingEncryptedUpload && (parent == null || mRemoteFolderToBeCreated)) { + Log_OC.d(TAG, "verifying remote parent folder exists: " + 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, "remote parent folder confirmed: " + remoteParentPath + ", id=" + parent.getFileId()); } - 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.e(TAG, "parent is null, cannot proceed: " + remoteParentPath + "," + " unlock token: " + mFolderUnlockToken); + return new RemoteOperationResult<>(false, "Parent folder not found", HttpStatus.SC_NOT_FOUND); } - - Log_OC.d(TAG, "remote parent folder confirmed: " + 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); } - // - resume of encrypted upload, then parent file exists already as unlock is only for direct parent - mFile.setParentId(parent.getFileId()); - // check if any parent is encrypted encryptedAncestor = FileStorageUtils.checkEncryptionStatus(parent, getStorageManager()); mFile.setEncrypted(encryptedAncestor); + if (encryptedAncestor && parent != null) { + // - resume of encrypted upload, then parent file exists already as unlock is only for direct parent + mFile.setParentId(parent.getFileId()); + } if (encryptedAncestor) { Log_OC.d(TAG, "⬆️🔗" + "encrypted upload");