From 7ec70a52569e90f05bff9ad3881166a98e493fba Mon Sep 17 00:00:00 2001 From: Linus Dietz Date: Sun, 18 Aug 2019 14:31:31 +0200 Subject: [PATCH] Fix Permissions of LaTeXintegration (#5134) * Differentiate Causes of Errors * Refactor Failure Mode * Remove unnecessary return * Remove redundant lines --- .../gui/texparser/ParseTexDialogViewModel.java | 12 +++++++++++- src/main/resources/l10n/JabRef_en.properties | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/texparser/ParseTexDialogViewModel.java b/src/main/java/org/jabref/gui/texparser/ParseTexDialogViewModel.java index ac2f0c596c6..10b4751ea39 100644 --- a/src/main/java/org/jabref/gui/texparser/ParseTexDialogViewModel.java +++ b/src/main/java/org/jabref/gui/texparser/ParseTexDialogViewModel.java @@ -1,6 +1,7 @@ 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; @@ -126,10 +127,19 @@ public void searchButtonClicked() { noFilesFound.set(false); successfulSearch.set(true); }) - .onFailure(dialogService::showErrorDialogAndWait) + .onFailure(this::handleFailure) .executeWith(taskExecutor); } + private void handleFailure(Exception exception) { + final boolean permissionProblem = exception instanceof IOException && exception.getCause() instanceof FileSystemException && exception.getCause().getMessage().endsWith("Operation not permitted"); + 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().isDirectory()) { throw new IOException(String.format("Invalid directory for searching: %s", directory)); diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index e61232b2099..7fc1fffd027 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -1373,6 +1373,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