Skip to content
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

Fix downloaded files moved to citation key dir #6608

Merged
merged 6 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where "null" appeared in generated BibTeX keys. [#6459](https://github.com/JabRef/jabref/issues/6459)
- We fixed an issue where the authors' names were incorrectly displayed in the authors' column when they were bracketed. [#6465](https://github.com/JabRef/jabref/issues/6465) [#6459](https://github.com/JabRef/jabref/issues/6459)
- We fixed an issue where importing certain unlinked files would result in an exception [#5815](https://github.com/JabRef/jabref/issues/5815)
- We fixed an issue where downloaded files would be moved to a directory named after the citationkey when no file directory pattern is specified [#6589](https://github.com/JabRef/jabref/issues/6589)

### Removed

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/logic/util/io/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public static String createDirNameFromPattern(BibDatabase database, BibEntry ent
String targetName = BracketedPattern.expandBrackets(directoryNamePattern, ';', entry, database);

if (targetName.isEmpty()) {
targetName = entry.getCiteKeyOptional().orElse("default");
return targetName;
Siedlerchr marked this conversation as resolved.
Show resolved Hide resolved
}

// Removes illegal characters from directory name
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/org/jabref/logic/cleanup/MoveFilesCleanupTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,19 @@ void movesFileWithFileDirPattern() throws Exception {
assertTrue(Files.exists(fileAfter));
}

@Test
void doesNotMoveFileWithEmptyFileDirPattern() throws Exception {
when(filePreferences.getFileDirPattern()).thenReturn("");
cleanup.cleanup(entry);

Path fileAfter = defaultFileFolder.resolve("test.pdf");
assertEquals(
Optional.of(FileFieldWriter.getStringRepresentation(new LinkedFile("", "test.pdf", ""))),
entry.getField(StandardField.FILE));
assertFalse(Files.exists(fileBefore));
assertTrue(Files.exists(fileAfter));
}

@Test
void movesFileWithSubdirectoryPattern() throws Exception {
when(filePreferences.getFileDirPattern()).thenReturn("[entrytype]/[year]/[auth]");
Expand Down
17 changes: 14 additions & 3 deletions src/test/java/org/jabref/logic/util/io/FileUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,26 @@ void invalidFilenameWithoutExtension() {
@Test
void testGetLinkedDirNameDefaultFullTitle() {
// bibkey - title
String fileNamePattern = "PDF/[year]/[auth]/[bibtexkey] - [fulltitle]";
String fileDirPattern = "PDF/[year]/[auth]/[bibtexkey] - [fulltitle]";
BibEntry entry = new BibEntry();
entry.setCiteKey("1234");
entry.setField(StandardField.TITLE, "mytitle");
entry.setField(StandardField.YEAR, "1998");
entry.setField(StandardField.AUTHOR, "A. Åuthör and Author, Bete");

assertEquals("PDF/1998/Åuthör/1234 - mytitle",
FileUtil.createDirNameFromPattern(null, entry, fileNamePattern));
assertEquals("PDF/1998/Åuthör/1234 - mytitle", FileUtil.createDirNameFromPattern(null, entry, fileDirPattern));
}

@Test
void testGetLinkedDirNamePatternEmpty() {
// bibkey - title
Siedlerchr marked this conversation as resolved.
Show resolved Hide resolved
BibEntry entry = new BibEntry();
entry.setCiteKey("1234");
entry.setField(StandardField.TITLE, "mytitle");
entry.setField(StandardField.YEAR, "1998");
entry.setField(StandardField.AUTHOR, "A. Åuthör and Author, Bete");

assertEquals("", FileUtil.createDirNameFromPattern(null, entry, ""));
}

@Test
Expand Down