Add auto-renaming of linked files on entry data change#13295
Add auto-renaming of linked files on entry data change#13295Siedlerchr merged 22 commits intoJabRef:mainfrom
Conversation
- Implemented a preference option under Linked files -> Linked file name conventions to enable auto-renaming of files when entry data changes (default: false). - Added functionality to listen for entry change events and rename files if the preference is enabled and the file name matches the defined pattern. - Ensured that no action is taken if the pattern is empty, as the file name would not match. - Considered scenarios where an entry has multiple files attached and handled them appropriately. - Added test cases to verify the new functionality.
|
Ensure if the target file exists, do not use that name, use (Note to us: File should be kept even there are binary equal files. Otherwise, it gets complicated. E.g., if the same file is attached to another entry). |
I am trying implementing it in " ERROR: Could not read timestamp for /Users//Documents/JabRef/Gen28_ - Hands on Machine Learning with Scikit Learn, Keras, and TensorFlow.pdf: java.nio.file.NoSuchFileException: /Users//Documents/JabRef/Gen28_ - Hands on Machine Learning with Scikit Learn, Keras, and TensorFlow.pdf " |
|
@LoayGhreeb Do you have some hints maybe? |
I don't think the problem is with the indexing itself. The I guess this loop could be happening if the same file is linked to two different entries. Could that be the case? Please try to investigate further by adding some breakpoints to understand why, and where this loop is happening. Also, if possible, please push the commits that reproduce this issue, either here or in a new branch so we can take a proper look and help without guessing what's going on. |
| * of duplicate markers. For example, if "paper (1).pdf" is already linked to the entry and is the correct format, | ||
| * the method will return "paper (1).pdf" instead of generating "paper (2).pdf". | ||
| */ | ||
| public static String generateUniqueFileName(Path targetDirectory, String proposedName, String fileAlreadyInUse) { |
There was a problem hiding this comment.
Method accepts null parameter 'fileAlreadyInUse' which violates modern Java practices of avoiding null parameters. Should use Optional instead.
|
when using
Case 1: File Exists but is Not Linked to the Entry: A new unique file name is suggested. |
koppor
left a comment
There was a problem hiding this comment.
I think, the loop comes from org.jabref.logic.cleanup.RenamePdfCleanup#cleanup
you can add some LOGGER.trace calls and adjust the log level (locally) to trace as desribed at https://devdocs.jabref.org/code-howtos/logging.html
Co-authored-by: Christoph <siedlerkiller@gmail.com>
|
I wired the listener to our CoarseGraindListener, because not at every single letter changes, the file should be renamed. I also fixed the logger output - not each fired event should be logged as default. More reading on logging available at https://devdocs.jabref.org/code-howtos/logging.html. Finally, I fixed the patterns for |
|
@trag-bot didn't find any issues in the code! ✅✨ |
|
Introduces some test failres on Windows, but I don't know yet why. Just documenting --> #13766 |
* upstream/main: (32 commits) Fix path (#13769) Mode aware consistency check (#13584) Refine JBang check (#13765) Add Language Server to the UI and add the integrity/consistency check (#13697) Fix/remove comment code (#13763) New Crowdin updates (#13760) Bump org.openrewrite.rewrite from 7.14.0 to 7.14.1 (#13757) Bump com.autonomousapps:dependency-analysis-gradle-plugin (#13756) Bump dev.langchain4j:langchain4j-bom from 1.2.0 to 1.3.0 in /versions (#13755) Bump jablib/src/main/resources/csl-locales from `fa56de1` to `e29c453` (#13754) Bump com.autonomousapps:dependency-analysis-gradle-plugin (#13753) Bump org.mockito:mockito-core from 5.18.0 to 5.19.0 in /versions (#13752) Bump actions/upload-pages-artifact from 3 to 4 (#13751) Migrate fetchers to Search.g4 ANTLR parser. (#13691) [Junie]: fix: resolve IllegalArgumentException for non-absolute URIs (#13669) Add auto-renaming of linked files on entry data change (#13295) Walkthrough additions (#13745) Switch from zulu to corretto (#13749) New Crowdin updates (#13747) Fix copy to (#13741) ...

Closes #11316
This PR introduces an option to automatically rename linked files when the associated entry data is modified. The feature is configurable in Preferences under Linked files -> Linked file name conventions, with a default setting of false. It also includes handling for entries with multiple attached files and adds relevant test cases.
Steps to test
Mandatory checks
CHANGELOG.mddescribed in a way that is understandable for the average user (if change is visible to the user)