Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notebook export canceled #188

Closed
siccovansas opened this issue Jun 2, 2018 · 6 comments
Closed

Notebook export canceled #188

siccovansas opened this issue Jun 2, 2018 · 6 comments

Comments

@siccovansas
Copy link

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
Copy link
Owner

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

@siccovansas
Copy link
Author

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
Copy link
Contributor

rdoeffinger commented Jul 21, 2020

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 added a commit to rdoeffinger/kolabnotes-android that referenced this issue Jul 21, 2020
When the ParcelFileDescriptor gets garbage collected that will
close the associated file descriptor.
Since the exporting happens async in a different block, we can
end up trying to write to a closed file descriptor.
To fix this, just pass the ParcelFileDescriptor to the object
doing the async export, so it will be destroyed only after we
have closed the stream we write to.
Fixes issue konradrenner#188.
@rdoeffinger
Copy link
Contributor

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

@konradrenner
Copy link
Owner

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

@rdoeffinger
Copy link
Contributor

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants