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 handling of relative-file storage and auto linking #11492

Merged
merged 6 commits into from
Jul 16, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Use LinkedHashSet instead of List for building the resulting list
  • Loading branch information
koppor committed Jul 16, 2024
commit a9a8ab19f5d3ac534be6d677e0c166d27abd791a
11 changes: 5 additions & 6 deletions src/main/java/org/jabref/model/database/BibDatabaseContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -159,7 +160,8 @@ public boolean isStudy() {
* @param preferences The fileDirectory preferences
*/
public List<Path> getFileDirectories(FilePreferences preferences) {
List<Path> fileDirs = new ArrayList<>(3);
// Paths are a) ordered and b) should be contained only once in the result
LinkedHashSet<Path> fileDirs = new LinkedHashSet<>(3);

Optional<Path> userFileDirectory = metaData.getUserFileDirectory(preferences.getUserAndHost()).map(dir -> getFileDirectoryPath(dir));
userFileDirectory.ifPresent(fileDirs::add);
Expand All @@ -180,18 +182,15 @@ public List<Path> getFileDirectories(FilePreferences preferences) {
LOGGER.warn("Parent path of database file {} is null. Falling back to {}.", dbPath, parentPath);
}
Objects.requireNonNull(parentPath, "BibTeX database parent path is null");
Path absolutePath = parentPath.toAbsolutePath();
if (!fileDirs.contains(absolutePath)) {
fileDirs.add(absolutePath);
}
fileDirs.add(parentPath.toAbsolutePath());
});
} else {
preferences.getMainFileDirectory()
.filter(path -> !fileDirs.contains(path))
.ifPresent(fileDirs::add);
}

return fileDirs;
return new ArrayList<>(fileDirs);
}

/**
Expand Down