-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Convert absolute paths to relative paths in Recent Files #14464
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
base: main
Are you sure you want to change the base?
Conversation
Removed commented-out section for relative/absolute helpers.
|
Thank you for your initial code. Please add missing tests. |
koppor
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code comments need to be added on the absolute/relative thing. There is no code comment about the where relative and absolute paths are stored etc.
I miss handling of #3590 (comment) - and your PR comment doesn't say anything about this.
Thus this PR reads like a quick fix than a well-through-through thing? I also miss screenshots.
| if (absolutePath == null) { | ||
| return null; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When can this happen? Maybe annotate paramter as @NonNull?
| try { | ||
| return workingDir.relativize(absolutePath); | ||
| } catch (Exception e) { | ||
| return absolutePath; // fallback |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do a LOGGER.error, because this should be fixed maybe?
| private Path toAbsolute(Path storedPath) { | ||
| if (storedPath == null) { | ||
| return null; | ||
| } | ||
| Path workingDir = Path.of("").toAbsolutePath(); | ||
| if (!storedPath.isAbsolute()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above.
| /** | ||
| * Adds the file to the top of the list. If it already is in the list, it is merely moved to the top. | ||
| * Adds the file to the top of the list. If it already is in the list, it is | ||
| * merely moved to the top. | ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why the reformatting here?
| public void newFile(Path file) { | ||
| removeItem(file); | ||
| this.addFirst(file); | ||
| this.addFirst(toRelative(file.toAbsolutePath())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, what?
| private Path toRelative(Path absolutePath) { | ||
| Path workingDir = Path.of("").toAbsolutePath(); | ||
| try { | ||
| return workingDir.relativize(absolutePath); | ||
| } catch (Exception e) { | ||
| return absolutePath; // fallback | ||
| } | ||
| } | ||
|
|
||
| private Path toAbsolute(Path storedPath) { | ||
| Path workingDir = Path.of("").toAbsolutePath(); | ||
| if (!storedPath.isAbsolute()) { | ||
| return workingDir.resolve(storedPath).normalize(); | ||
| } | ||
| return storedPath; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is duplicated code.
Strong indication that used at too many places.
Maybe you can use org.jabref.logic.util.io.FileUtil#relativize(java.nio.file.Path, java.util.List<java.nio.file.Path>) ?
| return new FileHistory(new ArrayList<>(list)); | ||
| } | ||
|
|
||
| private Path toRelative(Path absolutePath) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This definetitely needs a test
Closes #3590
This PR updates the Recent Files feature so that stored file paths are converted from absolute paths to project-relative paths. This fixes issues where Recent Files breaks when the project folder is moved or shared across machines. This improves portability and consistency for users working in multiple environments.
Steps to test
.bibfile located inside a folder (e.g., a project directory)..bibfile using the relative path.Mandatory checks
CHANGELOG.mdin a way understandable for the average user (if visible)