Skip to content

Conversation

paudelritij
Copy link
Contributor

@paudelritij paudelritij commented Sep 9, 2025

Closes #9798

This PR relinks files, if it has been moved by user.

Steps to test

  • Open `test-support\src\manual-tests\issue-9798\issue-9798.bib in JabRef
  • Start "Lookup" -> "Find unlinked files"
  • Start search
  • File will be relinked - and following shown in the message coloumn (under import tab): File relinked to entry minimal.pdf
D9481E13-FE08-4D7F-9A7D-CDFE9106959C

Mandatory checks

@jabref-machine
Copy link
Collaborator

Note that your PR will not be reviewed/accepted until you have gone through the mandatory checks in the description and marked each of them them exactly in the format of [x] (done), [ ] (not done yet) or [/] (not applicable).

@paudelritij
Copy link
Contributor Author

  1. I starting using existence code from AutoSetFileLinksUtil.java but found it could increase time complexity by using findAssociatedNotLinkedFiles() since it makes unnecessary call (in context of this feature) to while adding items in result (by calling findAssociatedFiles & findByBrokenLinkName), so I decided to create a separate method; and easy for testing as well.
  2. org.jabref.gui.externalfiles.AutoSetFileLinksUtil#findAssociatedNotLinkedFiles was adding same link two times so I suggest to make use of set instead of list.
  3. I had a file (a.pdf) in two places (dir/a.pdf & dir/sub-dir/a.pdf) however org.jabref.gui.externalfiles.AutoSetFileLinksUtil#findByBrokenLinkName was showing me file from sub-dir/a.pdf only so I suggest to show all related files having wantedbasename(forEach()). (one more point is that if b.txt link has been broken and findByBrokenLinkName() found file with wantedbasename to be as of b.pdf and then using code for findfirst() will add only b.pdf not b.txt which is the required one)

@paudelritij paudelritij marked this pull request as ready for review September 24, 2025 18:15
List<LinkedFile> filesToAdd = new ArrayList<>();

for (LinkedFile brokenLink : currentFiles) {
if (brokenLink.findIn(bibDatabase, preferences.getFilePreferences()).isPresent()) {
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this just duplicated? You add all those to entriesWithBrokenLInks that are not present so why checking them again here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not all.. only entries having at least one broken link... though it could be improved thnks for letting know

@Siedlerchr Siedlerchr added the status: changes-required Pull requests that are not yet complete label Sep 24, 2025
@Test
void fixBrokenLinksInLargeDatabase(@TempDir Path tempDir) throws IOException {
Path testRoot = tempDir.resolve("test");
List<BibEntry> entries = new ArrayList<>();
Copy link

Choose a reason for hiding this comment

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

Use modern Java data structures. Instead of using new ArrayList<>(), use List.of() for creating an empty list.

@jabref-machine
Copy link
Collaborator

Your pull request needs to link an issue correctly.

To ease organizational workflows, please link this pull-request to the issue with syntax as described in https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue:

Linking a pull request to an issue using a keyword

You can link a pull request to an issue by using a supported keyword in the pull request's description or in a commit message.

Examples

  • Fixes #xyz links pull-request to issue. Merging the PR will close the issue.
  • Fixes https://github.com/JabRef/jabref/issues/xyz links pull-request to issue. Merging the PR will close the issue.
  • Fixes https://github.com/Koppor/jabref/issues/xyz links pull-request to issue. Merging the PR will close the issue.
  • Fixes [#xyz](https://github.com/JabRef/jabref/issues/xyz) links pull-request to issue. Merging the PR will NOT close the issue.

Copy link

trag-bot bot commented Sep 25, 2025

@trag-bot didn't find any issues in the code! ✅✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: changes-required Pull requests that are not yet complete
Projects
None yet
Development

Successfully merging this pull request may close these issues.

If user moved file, it should simply be relinked - [Find Unlinked Files part]
3 participants