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

Return absolute path in case an absolute one is given #9433

Merged
merged 3 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue with the message that is displayed when fetcher returns an empty list of entries for given query. [#9195](https://github.com/JabRef/jabref/issues/9195)
- We fixed an issue where an exception was not logged correctly. [koppor#627](https://github.com/JabRef/koppor/issues/627)
- We fixed an issue where hitting enter on the search field within the preferences dialog closed the dialog. [koppor#630](https://github.com/koppor/jabref/issues/630)
- We fixed an issue where a user could not open an attached file in a new unsaved library. [#9386](https://github.com/JabRef/jabref/issues/9386)
- We fixed a typo within a connection error message. [koppor#625](https://github.com/koppor/jabref/issues/625)
- We fixed an issue where the 'close dialog' key binding was not closing the Preferences dialog. [#8888](https://github.com/jabref/jabref/issues/8888)
- We fixed an issue where editing entry's "date" field in library mode "biblatex" causes an uncaught exception. [#8747](https://github.com/JabRef/jabref/issues/8747)
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/jabref/model/util/FileHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ private static Optional<String> detectExtension(InputStream is, Metadata metaDat
* @param fileName The filename, may also be a relative path to the file
*/
public static Optional<Path> find(final BibDatabaseContext databaseContext, String fileName, FilePreferences filePreferences) {
Objects.requireNonNull(fileName, "fileName");
return find(fileName, databaseContext.getFileDirectories(filePreferences));
}

Expand All @@ -126,6 +127,16 @@ public static Optional<Path> find(final BibDatabaseContext databaseContext, Stri
* returning the first found file to match if any.
*/
public static Optional<Path> find(String fileName, List<Path> directories) {
if (directories.isEmpty()) {
// Fallback, if no directories to resolve are passed
Path path = Path.of(fileName);
if (path.isAbsolute()) {
return Optional.of(path);
} else {
return Optional.empty();
}
}

return directories.stream()
.flatMap(directory -> find(fileName, directory).stream())
.findFirst();
Expand Down