Skip to content

Kotlin conversion of UploadFileOperation - #17108

Open
hannesa2 wants to merge 1 commit into
masterfrom
KotlinUploadFileOperation
Open

hannesa2 wants to merge 1 commit into
masterfrom
KotlinUploadFileOperation

Conversation

@hannesa2

Copy link
Copy Markdown
Contributor

I was investigation how to change Wifi upload mechanism, and I found that causing class is still Java 馃憥
So I converted it in advance to Kotlin without changing anything in the logic. I hope that tests will check, if there is something now faulty

@hannesa2
hannesa2 force-pushed the KotlinUploadFileOperation branch 4 times, most recently from 118a028 to 9efa156 Compare June 6, 2026 09:13
@github-actions

github-actions Bot commented Jun 6, 2026

Copy link
Copy Markdown

APK file: https://github.com/nextcloud/android/actions/runs/27058366047/artifacts/7453194578
To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.
qrcode (please click on link to get QR code displayed)

Log_OC.d(TAG, "Creating temporal folder")
val temporalParent = targetFile.parentFile

if (!temporalParent!!.mkdirs() && !temporalParent.isDirectory) {
Log_OC.d(TAG, "Creating temporal folder")
val temporalParent = targetFile.parentFile

if (!temporalParent!!.mkdirs() && !temporalParent.isDirectory) {
}

Log_OC.d(TAG, "Creating temporal file")
if (!targetFile.createNewFile() && !targetFile.isFile) {
}

Log_OC.d(TAG, "Creating temporal file")
if (!targetFile.createNewFile() && !targetFile.isFile) {
} else {
`in` = FileInputStream(sourceFile)
}
out = FileOutputStream(targetFile)
private fun move(sourceFile: File, targetFile: File) {
if (targetFile != sourceFile) {
val expectedFolder = targetFile.parentFile
Files.createDirectories(expectedFolder!!.toPath())
val expectedFolder = targetFile.parentFile
Files.createDirectories(expectedFolder!!.toPath())

if (expectedFolder.isDirectory) {
Files.createDirectories(expectedFolder!!.toPath())

if (expectedFolder.isDirectory) {
if (!sourceFile.renameTo(targetFile)) {
if (expectedFolder.isDirectory) {
if (!sourceFile.renameTo(targetFile)) {
// try to copy and then delete
Files.createFile(targetFile.toPath())
Files.createFile(targetFile.toPath())
try {
FileInputStream(sourceFile).channel.use { inChannel ->
FileOutputStream(targetFile).channel.use { outChannel ->
@hannesa2
hannesa2 force-pushed the KotlinUploadFileOperation branch 2 times, most recently from b5e43ff to 317a04b Compare June 6, 2026 10:04
@github-actions

github-actions Bot commented Jun 6, 2026

Copy link
Copy Markdown

APK file: https://github.com/nextcloud/android/actions/runs/27059364136/artifacts/7453518059
To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.
qrcode (please click on link to get QR code displayed)

Signed-off-by: Hannes Achleitner <hannes.software@gmx.at>
@hannesa2
hannesa2 force-pushed the KotlinUploadFileOperation branch from 317a04b to 79ab1da Compare June 6, 2026 10:28
@github-actions

github-actions Bot commented Jun 6, 2026

Copy link
Copy Markdown

Codacy

SpotBugs

CategoryBaseNew
Bad practice3331
Correctness6764
Dodgy code215202
Experimental11
Internationalization77
Malicious code vulnerability22
Multithreaded correctness3126
Performance4137
Security1616
Total413386

@github-actions

github-actions Bot commented Jun 6, 2026

Copy link
Copy Markdown

APK file: https://github.com/nextcloud/android/actions/runs/27059855267/artifacts/7453666242
To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.
qrcode (please click on link to get QR code displayed)

@github-actions

github-actions Bot commented Jun 6, 2026

Copy link
Copy Markdown

blue-Light-Screenshot test failed, but no output was generated. Maybe a preliminary stage failed.

@github-actions

Copy link
Copy Markdown

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

(If you believe you should not receive this message, you can add yourself to the blocklist.)

@alperozturk96 alperozturk96 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this.

I'd be more comfortable taking an incremental approach, for example, first extracting smaller pieces into separate Kotlin classes and then gradually converting the remaining parts. That would make the changes easier to review, test, and debug if anything goes wrong.

@hannesa2

hannesa2 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

@alperozturk96 After 5 weeks. you want to multiply the afford here by splitting it in smaller junks.
As this is just the output of
image

you should re-think your comfortable it's-better-for-me-way

@tobiasKaminsky

Copy link
Copy Markdown
Member

@hannesa2

Alper and me discussed this and to put it in bigger context, we struggle a bit with "automatic" java -> kotlin conversions, especially when it comes to big/central classes that are not easy to test manually (in opposite to UI related classes).
So my/our idea is now to test with your PR

  • check code coverage of old java file
  • add missing tests
  • test tests with your migrated code
  • some test

This will help us, not only for this PR, but also for upcoming semi/automated code conversions to see if this approach works.

I wanna thank you for helping with this project and PR 馃帀

@alperozturk96

alperozturk96 commented Jul 13, 2026 •

Copy link
Copy Markdown
Collaborator

It seems like the following cases are currently missing on master and would be good to have covered before the Kotlin conversion:

  • FileUploaderIT doesn't seem to be used. Already contains tests for UploadFileOperation.
  • UploadIT covers some UploadFileOperation scenarios, but not all combinations.
  • The constructor guards in UploadFileOperation aren't tested.
  • The encryptedUpload path isn't covered.
  • The early return cases are missing as well (e.g. TextUtils.isEmpty(getStoragePath()), !localFile.exists(), etc.).
  • I also couldn't find tests covering methods like obtainNewOCFileToUpload, getNewAvailableRemotePath, existsFile, and createNewOCFile.

Since this class is responsible for all uploads (AutoUpload, normal upload, etc.).

@hannesa2

hannesa2 commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

I wanna thank you for helping with this project and PR 馃帀

@tobiasKaminsky I want to tell my my frustration. I made this, I didn't changed anything on the logic and it was working for me. But as it is not yours, you all put the brake and hesitate to accept it. -Ok, it's your choice-

But what does this mean for me ? It was just an intermediate step for me to solving an other (later) issue. But as this is not accepted, and dedicated to be pointless and to die, I stopped my afford to Nextcloud complete and unfortunately I've to keep on ownCloud. But the good thing for, there is the situation the same bad one.

Looks like a common behaviour "I/we know it better", so it's better to do nothing instead of moving forward.

Btw, you have at least a lot of CI test, but as they fail and nobody takes care about it and ignores them, this all CI checks are complete pointless and just waste of time of everyone.
image

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants