Skip to content

Commit

Permalink
Merge pull request #210 from rdoeffinger/issue188
Browse files Browse the repository at this point in the history
Fix native file descriptor being closed while still exporting.
  • Loading branch information
konradrenner authored Jul 30, 2020
2 parents 32d71f2 + 49978f4 commit c4994fe
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1196,9 +1196,8 @@ public void onActivityResult(int requestCode, int resultCode,
}

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

new ExportNotebook(getActivity(), uri, fileOutputStream).execute(activeAccount.getAccount(), activeAccount.getRootFolder(), notebookName);
new ExportNotebook(getActivity(), uri, pfd).execute(activeAccount.getAccount(), activeAccount.getRootFolder(), notebookName);
}catch (FileNotFoundException e){
Log.e("result", e.getMessage(), e);
NotificationManager notificationManager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
Expand Down Expand Up @@ -1331,13 +1330,13 @@ private void exportNotebooks(){
class ExportNotebook extends AsyncTask<String, Void, String>{

private final Context context;
private final OutputStream pathToZIP;
private final ParcelFileDescriptor pfd;
private final Uri fileUri;
private final Random random;

ExportNotebook(Context context, Uri fileUri, OutputStream pathToZIP){
ExportNotebook(Context context, Uri fileUri, ParcelFileDescriptor pfd){
this.context = context;
this.pathToZIP = pathToZIP;
this.pfd = pfd;
random = new Random();
this.fileUri = fileUri;
}
Expand All @@ -1347,6 +1346,7 @@ class ExportNotebook extends AsyncTask<String, Void, String>{
protected String doInBackground(String... params) {
try {
Log.d("export", Arrays.toString(params));
FileOutputStream pathToZIP = new FileOutputStream(pfd.getFileDescriptor());
Notebook notebook = notebookRepository.getBySummary(params[0], params[1], params[2]);
List<Note> fromNotebook = notesRepository.getFromNotebookWithDescriptionLoaded(params[0], params[1], notebook.getIdentification().getUid(), new NoteSorting());

Expand All @@ -1358,6 +1358,7 @@ protected String doInBackground(String... params) {


repository.exportNotebook(notebook, new KolabNotesParserV3(), pathToZIP);
pathToZIP.close();

Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(fileUri);
Expand Down

0 comments on commit c4994fe

Please sign in to comment.