Skip to content

Commit

Permalink
Fix attach file does not relativize file path (#4252)
Browse files Browse the repository at this point in the history
* attempt at attach file relative file making

* add method for making path relative

* set new path when chosing another file

* add changelog entry

* Return new relatizived path
  • Loading branch information
Siedlerchr authored Aug 10, 2018
1 parent 89ee885 commit 7b29fe3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We fixed an issue where the preview pane in entry preview in preferences wasn't showing the citation style selected [#3849](https://github.com/JabRef/jabref/issues/3849)
- We fixed an issue where the default entry preview style still contained the field `review`. The field `review` in the style is now replaced with comment to be consistent with the entry editor [#4098](https://github.com/JabRef/jabref/issues/4098)
- We fixed an issue where users were vulnerable to XXE attacks during parsing [#4229](https://github.com/JabRef/jabref/issues/4229)
- We fixed an issue where files added via the "Attach file" contextmenu of an entry were not made relative. [#4201](https://github.com/JabRef/jabref/issues/4201)
- We fixed an issue where files added via the "Attach file" contextmenu of an entry were not made relative. [#4201](https://github.com/JabRef/jabref/issues/4201) and [#4241](https://github.com/JabRef/jabref/issues/4241)
- We fixed an issue where author list parser can't generate bibtex for Chinese author. [#4169](https://github.com/JabRef/jabref/issues/4169)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,17 @@ public void openBrowseDialog() {
dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(path -> {
// Store the directory for next time:
preferences.setWorkingDir(path);
link.set(relativize(path));

// If the file is below the file directory, make the path relative:
List<Path> fileDirectories = database.getFileDirectoriesAsPaths(preferences.getFileDirectoryPreferences());
path = FileUtil.shortenFileName(path, fileDirectories);

link.set(path.toString());
setExternalFileTypeByExtension(link.getValueSafe());
});
}

public void setValues(LinkedFile linkedFile) {
description.set(linkedFile.getDescription());
link.set(linkedFile.getLink());

Path linkPath = Paths.get(linkedFile.getLink());
link.set(relativize(linkPath));

selectedExternalFileType.setValue(null);

Expand Down Expand Up @@ -128,4 +126,9 @@ public LinkedFile getNewLinkedFile() {
return new LinkedFile(description.getValue(), link.getValue(), monadicSelectedExternalFileType.map(ExternalFileType::toString).getOrElse(""));
}

private String relativize(Path filePath) {
List<Path> fileDirectories = database.getFileDirectoriesAsPaths(preferences.getFileDirectoryPreferences());
return FileUtil.shortenFileName(filePath, fileDirectories).toString();
}

}

0 comments on commit 7b29fe3

Please sign in to comment.