From a779428c0ce7c4bfd7cdeb69fc64168588c8d827 Mon Sep 17 00:00:00 2001 From: aloofluo <945517787@qq.com> Date: Mon, 10 May 2021 22:31:27 +0800 Subject: [PATCH 1/6] fix for issue #7719, user should input absolute path --- .../java/org/jabref/gui/groups/GroupDialogViewModel.java | 6 ++++-- .../java/org/jabref/gui/util/DefaultFileUpdateMonitor.java | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java b/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java index 05233f2abdc..0e19bc69f60 100644 --- a/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java +++ b/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java @@ -227,8 +227,9 @@ private void setupValidation() { if (StringUtil.isBlank(input)) { return false; } else { - Path texFilePath = preferencesService.getWorkingDir().resolve(input); - if (!Files.isRegularFile(texFilePath)) { + // we don't need to add the working dir before checking, let user input absolute path + Path inputPath = Path.of(input); + if (!Files.isRegularFile(inputPath)) { return false; } return FileUtil.getFileExtension(input) @@ -335,6 +336,7 @@ public AbstractGroup resultConverter(ButtonType button) { FieldFactory.parseField(autoGroupPersonsFieldProperty.getValue().trim())); } } else if (typeTexProperty.getValue()) { + // issue 7719: if texGroupFilePath is not absolute, path to Jabref will be added, which is wrong resultingGroup = TexGroup.create( groupName, groupHierarchySelectedProperty.getValue(), diff --git a/src/main/java/org/jabref/gui/util/DefaultFileUpdateMonitor.java b/src/main/java/org/jabref/gui/util/DefaultFileUpdateMonitor.java index 588e7616b07..2a4bc417b51 100644 --- a/src/main/java/org/jabref/gui/util/DefaultFileUpdateMonitor.java +++ b/src/main/java/org/jabref/gui/util/DefaultFileUpdateMonitor.java @@ -87,6 +87,7 @@ private void notifyAboutChange(Path path) { public void addListenerForFile(Path file, FileUpdateListener listener) throws IOException { if (isActive()) { // We can't watch files directly, so monitor their parent directory for updates + // toAbsolutePath() will add the path to Jabref as home directory to file, if file is not a absolute path Path directory = file.toAbsolutePath().getParent(); directory.register(watcher, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_MODIFY); listeners.put(file, listener); From 5f11f2d43454650dd544649eab3a70685a14504c Mon Sep 17 00:00:00 2001 From: aloofluo <945517787@qq.com> Date: Mon, 10 May 2021 23:17:22 +0800 Subject: [PATCH 2/6] fix for issue #7719, v1 --- src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java | 4 +++- .../java/org/jabref/gui/util/DefaultFileUpdateMonitor.java | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java b/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java index 05233f2abdc..49becd539d6 100644 --- a/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java +++ b/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java @@ -335,10 +335,12 @@ public AbstractGroup resultConverter(ButtonType button) { FieldFactory.parseField(autoGroupPersonsFieldProperty.getValue().trim())); } } else if (typeTexProperty.getValue()) { + // issue 7719: add workingDir to filepath if it is relative + Path inputPath = preferencesService.getWorkingDir().resolve(Path.of(texGroupFilePathProperty.getValue().trim())); resultingGroup = TexGroup.create( groupName, groupHierarchySelectedProperty.getValue(), - Path.of(texGroupFilePathProperty.getValue().trim()), + inputPath, new DefaultAuxParser(new BibDatabase()), Globals.getFileUpdateMonitor(), currentDatabase.getMetaData()); diff --git a/src/main/java/org/jabref/gui/util/DefaultFileUpdateMonitor.java b/src/main/java/org/jabref/gui/util/DefaultFileUpdateMonitor.java index 588e7616b07..2a4bc417b51 100644 --- a/src/main/java/org/jabref/gui/util/DefaultFileUpdateMonitor.java +++ b/src/main/java/org/jabref/gui/util/DefaultFileUpdateMonitor.java @@ -87,6 +87,7 @@ private void notifyAboutChange(Path path) { public void addListenerForFile(Path file, FileUpdateListener listener) throws IOException { if (isActive()) { // We can't watch files directly, so monitor their parent directory for updates + // toAbsolutePath() will add the path to Jabref as home directory to file, if file is not a absolute path Path directory = file.toAbsolutePath().getParent(); directory.register(watcher, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_MODIFY); listeners.put(file, listener); From 57f18615439ce47712b0cdeba07506faee07d9f4 Mon Sep 17 00:00:00 2001 From: aloofluo <945517787@qq.com> Date: Thu, 20 May 2021 23:30:02 +0800 Subject: [PATCH 3/6] fix for issue #7719, v3 --- CHANGELOG.md | 1 + .../jabref/gui/groups/GroupDialogViewModel.java | 16 ++++++++++++---- .../gui/util/DefaultFileUpdateMonitor.java | 1 - 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8606dfa7ed8..a024b2ae4c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -90,6 +90,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We fixed an issue where the article title with colon fails to download the arXiv link (pdf file). [#7660](https://github.com/JabRef/issues/7660) - We fixed an issue where the keybinding for delete entry did not work on the main table [7580](https://github.com/JabRef/jabref/pull/7580) - We fixed an issue where the RFC fetcher is not compatible with the draft [7305](https://github.com/JabRef/jabref/issues/7305) +- We fixed an issue where the `Aux file` on `Edit group` doesn't support relative sub-directories path to import. [#7719](https://github.com/JabRef/jabref/issues/7719). ### Removed diff --git a/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java b/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java index 49becd539d6..11fe996adcd 100644 --- a/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java +++ b/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java @@ -227,7 +227,7 @@ private void setupValidation() { if (StringUtil.isBlank(input)) { return false; } else { - Path texFilePath = preferencesService.getWorkingDir().resolve(input); + Path texFilePath = getAbsoluteTexGroupPath(input); if (!Files.isRegularFile(texFilePath)) { return false; } @@ -263,6 +263,16 @@ private void setupValidation() { }); } + /** + * gets the absolute path relative to getLatexFileDirectory, if given a relative path + * @param input the user input path + * @return an absolute path + */ + private Path getAbsoluteTexGroupPath(String input) { + Optional latexFileDirectory = currentDatabase.getMetaData().getLatexFileDirectory(preferencesService.getUser()); + return latexFileDirectory.map(path -> path.resolve(input)).orElse(Path.of(input)); + } + public void validationHandler(Event event) { ValidationStatus validationStatus = validator.getValidationStatus(); if (validationStatus.getHighestMessage().isPresent()) { @@ -335,12 +345,10 @@ public AbstractGroup resultConverter(ButtonType button) { FieldFactory.parseField(autoGroupPersonsFieldProperty.getValue().trim())); } } else if (typeTexProperty.getValue()) { - // issue 7719: add workingDir to filepath if it is relative - Path inputPath = preferencesService.getWorkingDir().resolve(Path.of(texGroupFilePathProperty.getValue().trim())); resultingGroup = TexGroup.create( groupName, groupHierarchySelectedProperty.getValue(), - inputPath, + Path.of(texGroupFilePathProperty.getValue().trim()), new DefaultAuxParser(new BibDatabase()), Globals.getFileUpdateMonitor(), currentDatabase.getMetaData()); diff --git a/src/main/java/org/jabref/gui/util/DefaultFileUpdateMonitor.java b/src/main/java/org/jabref/gui/util/DefaultFileUpdateMonitor.java index 2a4bc417b51..588e7616b07 100644 --- a/src/main/java/org/jabref/gui/util/DefaultFileUpdateMonitor.java +++ b/src/main/java/org/jabref/gui/util/DefaultFileUpdateMonitor.java @@ -87,7 +87,6 @@ private void notifyAboutChange(Path path) { public void addListenerForFile(Path file, FileUpdateListener listener) throws IOException { if (isActive()) { // We can't watch files directly, so monitor their parent directory for updates - // toAbsolutePath() will add the path to Jabref as home directory to file, if file is not a absolute path Path directory = file.toAbsolutePath().getParent(); directory.register(watcher, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_MODIFY); listeners.put(file, listener); From 89c95fa8b74d165f5e1950860509f63e40160b30 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Fri, 21 May 2021 00:06:30 +0200 Subject: [PATCH 4/6] Update src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java Co-authored-by: Jonatan Asketorp <2598631+k3KAW8Pnf7mkmdSMPHz27@users.noreply.github.com> --- src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java b/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java index 11fe996adcd..47f1d4e254c 100644 --- a/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java +++ b/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java @@ -264,7 +264,7 @@ private void setupValidation() { } /** - * gets the absolute path relative to getLatexFileDirectory, if given a relative path + * Gets the absolute path relative to the LatexFileDirectory, if given a relative path * @param input the user input path * @return an absolute path */ From aae330f0f7d5cef0ff0738d72e216c883703b980 Mon Sep 17 00:00:00 2001 From: aloofluo <945517787@qq.com> Date: Fri, 21 May 2021 10:52:20 +0800 Subject: [PATCH 5/6] fixes for 7719, reject if no LatexGroupPath is set --- .../java/org/jabref/gui/groups/GroupDialogViewModel.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java b/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java index 6661fd1aeef..14534d0912a 100644 --- a/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java +++ b/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java @@ -227,8 +227,8 @@ private void setupValidation() { if (StringUtil.isBlank(input)) { return false; } else { - Path inputPath = Path.of(input); - if (!Files.isRegularFile(inputPath)) { + Path inputPath = getAbsoluteTexGroupPath(input); + if (!inputPath.isAbsolute() || !Files.isRegularFile(inputPath)) { return false; } return FileUtil.getFileExtension(input) @@ -266,7 +266,7 @@ private void setupValidation() { /** * Gets the absolute path relative to the LatexFileDirectory, if given a relative path * @param input the user input path - * @return an absolute path + * @return an absolute path if LatexFileDirectory exists; otherwise, returns input */ private Path getAbsoluteTexGroupPath(String input) { Optional latexFileDirectory = currentDatabase.getMetaData().getLatexFileDirectory(preferencesService.getUser()); From e7c8131996b956063eeba46a473566d83b9ed3ea Mon Sep 17 00:00:00 2001 From: aloofluo <945517787@qq.com> Date: Fri, 21 May 2021 10:55:12 +0800 Subject: [PATCH 6/6] fixes for 7719, delete a comment --- src/main/java/org/jabref/gui/util/DefaultFileUpdateMonitor.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/util/DefaultFileUpdateMonitor.java b/src/main/java/org/jabref/gui/util/DefaultFileUpdateMonitor.java index 2a4bc417b51..588e7616b07 100644 --- a/src/main/java/org/jabref/gui/util/DefaultFileUpdateMonitor.java +++ b/src/main/java/org/jabref/gui/util/DefaultFileUpdateMonitor.java @@ -87,7 +87,6 @@ private void notifyAboutChange(Path path) { public void addListenerForFile(Path file, FileUpdateListener listener) throws IOException { if (isActive()) { // We can't watch files directly, so monitor their parent directory for updates - // toAbsolutePath() will add the path to Jabref as home directory to file, if file is not a absolute path Path directory = file.toAbsolutePath().getParent(); directory.register(watcher, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_MODIFY); listeners.put(file, listener);