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

Fix Permissions of LaTeXintegration #5134

Merged
merged 4 commits into from
Aug 18, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package org.jabref.gui.texparser;

import java.io.IOException;
import java.nio.file.FileSystemException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -117,18 +119,33 @@ public void searchButtonClicked() {
noFilesFound.set(true);
searchInProgress.set(true);
successfulSearch.set(false);

})
.onFinished(() -> searchInProgress.set(false))
.onSuccess(newRoot -> {
root.set(newRoot);
noFilesFound.set(false);
successfulSearch.set(true);
})
.onFailure(dialogService::showErrorDialogAndWait)
.onFailure(handleFailure())
.executeWith(taskExecutor);
}

private Consumer<Exception> handleFailure() {
return exception -> {
root.set(null);
noFilesFound.set(true);
searchInProgress.set(false);
successfulSearch.set(false);

final boolean permissionProblem = exception instanceof IOException && exception.getCause() instanceof FileSystemException && exception.getCause().getMessage().endsWith("Operation not permitted");
Copy link
Member

Choose a reason for hiding this comment

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

Does it make sense to move this code to dialogService.showErrorDialogAndWait(exception) so that access issues in other parts of JabRef are treated similarly?

Copy link
Member Author

Choose a reason for hiding this comment

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

I wouldn't do that because the dialogService is a global thing, whereas how we handle the exception here is quite special.

Copy link
Member

Choose a reason for hiding this comment

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

ok, so the same exception but e.g. thrown while opening a bib file should still be displayed in the default error dialog with the stack trace instead of by the specialized permission problem dialog?

Copy link
Member

Choose a reason for hiding this comment

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

I am not sure, but I think that in those cases the selection file dialog should show a warning like this. Here the problem is related to the deep search in all subdirectories, if I understood properly.

Warning

Copy link
Member

Choose a reason for hiding this comment

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

At least add a complete error message with stack trace to the log. I hate error messages without stack traces.

if (permissionProblem) {
dialogService.showErrorDialogAndWait(String.format(Localization.lang("JabRef does not have permission to access %s"), exception.getCause().getMessage()));
} else {
dialogService.showErrorDialogAndWait(exception);
}
};
}

private FileNodeViewModel searchDirectory(Path directory) throws IOException {
if (directory == null || !directory.toFile().exists() || !directory.toFile().isDirectory()) {
throw new IOException("An error occurred while searching an invalid directory.");
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1381,6 +1381,7 @@ Open\ %0\ file=Open %0 file

Cannot\ delete\ file=Cannot delete file
File\ permission\ error=File permission error
JabRef\ does\ not\ have\ permission\ to\ access\ %s=JabRef does not have permission to access %s
Push\ to\ %0=Push to %0
Path\ to\ %0=Path to %0
Convert=Convert
Expand Down