diff --git a/CHANGELOG.md b/CHANGELOG.md index 4dacb4bb5aa..049eda99642 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv ### Fixed +- We fixed an issue where directory check for relative path was not handled properly under library properties. [#13017](https://github.com/JabRef/jabref/issues/13017) - We fixed an issue where the option for which method to use when parsing plaintext citations was unavailable in the 'Create New Entry' tool. [#8808](https://github.com/JabRef/jabref/issues/8808) ### Removed diff --git a/jabgui/src/main/java/org/jabref/gui/libraryproperties/general/GeneralPropertiesViewModel.java b/jabgui/src/main/java/org/jabref/gui/libraryproperties/general/GeneralPropertiesViewModel.java index bff693ee35d..0851d198dd4 100644 --- a/jabgui/src/main/java/org/jabref/gui/libraryproperties/general/GeneralPropertiesViewModel.java +++ b/jabgui/src/main/java/org/jabref/gui/libraryproperties/general/GeneralPropertiesViewModel.java @@ -196,24 +196,40 @@ public StringProperty laTexFileDirectoryProperty() { } private Path getBrowseDirectory(String configuredDir) { + Optional libPath = this.databaseContext.getDatabasePath(); + Path workingDir = preferences.getFilePreferences().getWorkingDirectory(); + + if (libPath.isEmpty()) { + Path potentialAbsolutePath = Path.of(configuredDir); + return Files.isDirectory(potentialAbsolutePath) ? potentialAbsolutePath : workingDir; + } if (configuredDir.isEmpty()) { - return preferences.getFilePreferences().getWorkingDirectory(); + return workingDir; } - Optional foundPath = this.databaseContext.getFileDirectories(preferences.getFilePreferences()).stream() - .filter(path -> path.toString().endsWith(configuredDir)) - .filter(Files::exists).findFirst(); - if (foundPath.isEmpty()) { - dialogService.notify(Localization.lang("Path %0 could not be resolved. Using working dir.", configuredDir)); - return preferences.getFilePreferences().getWorkingDirectory(); + Path configuredPath = libPath.get().getParent().resolve(configuredDir).normalize(); + + // configuredDir can be input manually, which may lead it to being invalid + if (!Files.isDirectory(configuredPath)) { + dialogService.notify(Localization.lang("Path %0 could not be resolved. Using working directory.", configuredDir)); + return workingDir; } - return foundPath.get(); + + return configuredPath; } private ValidationMessage validateDirectory(String directoryPath, String messageKey) { + Optional libPath = this.databaseContext.getDatabasePath(); + Path potentialAbsolutePath = Path.of(directoryPath); + + // check absolute path separately in case of unsaved libraries + if (libPath.isEmpty() && Files.isDirectory(potentialAbsolutePath)) { + return null; + } try { - Path path = Path.of(directoryPath); - if (!Files.isDirectory(path)) { + if (!libPath.map(p -> p.getParent().resolve(directoryPath).normalize()) + .map(Files::isDirectory) + .orElse(false)) { return ValidationMessage.error( Localization.lang("File directory '%0' not found.\nCheck \"%1\" file directory path.", directoryPath, messageKey) ); diff --git a/jablib/src/main/resources/l10n/JabRef_en.properties b/jablib/src/main/resources/l10n/JabRef_en.properties index 787fd76c617..ad1042ff3a3 100644 --- a/jablib/src/main/resources/l10n/JabRef_en.properties +++ b/jablib/src/main/resources/l10n/JabRef_en.properties @@ -1090,7 +1090,7 @@ Expected\ syntax\ for\ --fetch\='\:'=Expected syntax f Library-specific\ file\ directory=Library-specific file directory User-specific\ file\ directory=User-specific file directory LaTeX\ file\ directory=LaTeX file directory -Path\ %0\ could\ not\ be\ resolved.\ Using\ working\ dir.=Path %0 could not be resolved. Using working dir. +Path\ %0\ could\ not\ be\ resolved.\ Using\ working\ directory.=Path %0 could not be resolved. Using working directory. You\ must\ enter\ an\ integer\ value\ in\ the\ interval\ 1025-65535=You must enter an integer value in the interval 1025-65535