konradrenner / kolabnotes-android

Note taking app with integrated Kolab sync
GNU Lesser General Public License v3.0
68 stars 17 forks source link

Notebook export canceled #188

Closed siccovansas closed 4 years ago

siccovansas commented 6 years ago

I exported my notebooks many times before, but I now receive the following error when trying to export: Notebook export canceled local/Notes/Notes/write failed: EBADF (Bad file descriptor)

Any idea what's happening and how to fix it?

konradrenner commented 6 years ago

Did you install any Android update? Did you change any permessions?

siccovansas commented 6 years ago

Thanks for your response!

I did not change any permissions, but when I checked the permissions the storage permission was turned off. I turned it on but the export still fails (also after a reboot of the phone). After the exports started failing I updated the app using F-droid to version 3.1.3.

I don't see EBADF error anymore, but I do get the following error: Notebook export canceled local/Notes/Notes / Attempt to invoke virtual method 'org.kore.kolab.notes.Identification org.kore.kolab.notes.Notebook.getIdentification()' on a null object reference

rdoeffinger commented 4 years ago

I am getting the same. I am pretty sure the problem is here:

                ParcelFileDescriptor pfd = getActivity().getContentResolver().openFileDescriptor(uri, "w");
                FileOutputStream fileOutputStream = new FileOutputStream(pfd.getFileDescriptor());

                new ExportNotebook(getActivity(), uri, fileOutputStream).execute(activeAccount.getAccount(), activeAccount.getRootFolder(), notebookName);

I think you need to pass the ParcelFileDescriptor to ExportNotebook, otherwise when the garbage collector cleans it up the file gets closed. You probably can't reproduce because you do not have enough notes for the garbage collector to run before everything is written. I'd really appreciate it if you could release a fix, since I am unable to migrate my data to a different phone because of this (the IMAP sync is broken for some unknown other reason and results only in NOT_LOADED entries, that one seems much harder to debug).

There are some other annoying issues, for example the name of the zip file is used to select the notebook to export, which means you just get an empty file when you change it. That's probably what caused he "null object reference" from the previous message (as the dialog to select the save location automatically renames the file if it would overwrite something, so every time you want to export you have to delete the previous export first).

rdoeffinger commented 4 years ago

I sent a pull request and I tested that it does indeed fix the issue.

konradrenner commented 4 years ago

Hi, thank you for the fix! I will asap release it (maybe next week).

rdoeffinger commented 4 years ago

Thanks, to not put you under unnecessary pressure I'll add that with some trial-and-error and zip recovery tools I managed to get a backup out already, so this is not an immediate issue for me anymore. However, after importing the file none of the notes have any tags or attachments anymore. Is that expected or is this either due to the export not being complete or some other bug? I have to admit I am a bit hindered in the debug by the logic being split over 3 repos, I tried to integrate them all together (so that Android Studio would compile all of them at once) to make trials and debugging easier, but I didn't figure out how to avoid the missing references to java.beans.Beans and some similar things in kore-javamail...