Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public TarDirWalker(Path basePath, TarArchiveOutputStream tarArchiveOutputStream
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
if (!dir.equals(basePath)) {
tarArchiveOutputStream.putArchiveEntry(new TarArchiveEntry(FilePathUtil.relativize(basePath, dir)));
tarArchiveOutputStream.closeArchiveEntry();
}
return FileVisitResult.CONTINUE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,32 @@ public void copyToNonExistingContainer() throws Exception {
} catch (NotFoundException ignored) {
}
}

@Test
public void copyDirWithLastAddedTarEnryEmptyDir() throws Exception{
// create a temp dir
Path localDir = Files.createTempDirectory("");
localDir.toFile().deleteOnExit();
// create sub-dir with name b
Path emptyDir = Files.createTempDirectory(localDir.resolve("b"), "");
emptyDir.toFile().deleteOnExit();
// creaet sub-dir with name a
Path dirWithFile = Files.createTempDirectory(localDir.resolve("a"), "");
dirWithFile.toFile().deleteOnExit();
// create file in sub-dir b, name or conter are irrelevant
Path file = Files.createTempFile(dirWithFile.resolve("file"), "", "");
file.toFile().deleteOnExit();

// create a test container
CreateContainerResponse container = dockerClient.createContainerCmd("progrium/busybox:latest")
.withCmd("/bin/sh", "-c", "while true; do sleep 9999; done")
.exec();
// start the container
dockerClient.startContainerCmd(container.getId()).exec();
// copy data from local dir to container
dockerClient.copyArchiveToContainerCmd(container.getId())
.withHostResource(localDir.toString())
.exec();
}

}