Skip to content

Commit

Permalink
fix(compress): 🐛 null appears on entry paths on a wildcard compress
Browse files Browse the repository at this point in the history
fix #22
  • Loading branch information
Dougniel committed Dec 23, 2022
1 parent 2337613 commit 0f0876d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/nc/opt/util/J7zip.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static void compress(String name, String password, String... files) throw
}

private static void addToArchiveCompression(SevenZOutputFile out, File file, String dir) throws IOException {
String name = dir + File.separator + file.getName();
String name = (dir != null ? dir + File.separator : "") + file.getName();
if (file.isFile()) {
SevenZArchiveEntry entry = out.createArchiveEntry(file, name);
out.putArchiveEntry(entry);
Expand Down
34 changes: 34 additions & 0 deletions src/test/java/nc/opt/uil/j7zip/Tests.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,40 @@ public void testListArrchiveFiles() throws IOException {
Paths.get("target/archive.7z").toFile().delete();
}

@Test
public void testCompressDirectory() throws IOException {
// compress
int exitCode = new CommandLine(new J7zip()).execute(new String[] { "a", "target/archive.7z", "src" });
restoreStreams();

String err = new String(this.err.toByteArray());
if (!err.isEmpty()) {
System.err.println(err);
throw new AssertionFailedError(err);
}
assertEquals(0, exitCode);

// list contents of file
setUpStreams();
exitCode = new CommandLine(new J7zip()).execute(new String[] { "l", "target/archive.7z" });
restoreStreams();

err = new String(this.err.toByteArray());
if (!err.isEmpty()) {
System.err.println(err);
throw new AssertionFailedError(err);
}
assertEquals(0, exitCode);

String[] lines = new String(this.out.toByteArray()).split("\n");
assertNotEquals(0, lines.length);
for (String entry : lines) {
assertTrue(entry.startsWith("src/"), "entry not starts with src/ : " + entry);
}

Paths.get("target/archive.7z").toFile().delete();
}

/**
* Test with a archive file compressed by 7z tool
*/
Expand Down

0 comments on commit 0f0876d

Please sign in to comment.