Skip to content

Commit b3f51b6

Browse files
author
Marcus Linke
committed
Merge branch 'master' of https://github.com/denlap007/docker-java into denlap007-master
2 parents 8b5bada + d2b2a2d commit b3f51b6

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/main/java/com/github/dockerjava/core/util/TarDirWalker.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public TarDirWalker(Path basePath, TarArchiveOutputStream tarArchiveOutputStream
2626
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
2727
if (!dir.equals(basePath)) {
2828
tarArchiveOutputStream.putArchiveEntry(new TarArchiveEntry(FilePathUtil.relativize(basePath, dir)));
29+
tarArchiveOutputStream.closeArchiveEntry();
2930
}
3031
return FileVisitResult.CONTINUE;
3132
}

src/test/java/com/github/dockerjava/core/command/CopyArchiveToContainerCmdImplTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,32 @@ public void copyToNonExistingContainer() throws Exception {
9090
} catch (NotFoundException ignored) {
9191
}
9292
}
93+
94+
@Test
95+
public void copyDirWithLastAddedTarEnryEmptyDir() throws Exception{
96+
// create a temp dir
97+
Path localDir = Files.createTempDirectory("");
98+
localDir.toFile().deleteOnExit();
99+
// create sub-dir with name b
100+
Path emptyDir = Files.createTempDirectory(localDir.resolve("b"), "");
101+
emptyDir.toFile().deleteOnExit();
102+
// creaet sub-dir with name a
103+
Path dirWithFile = Files.createTempDirectory(localDir.resolve("a"), "");
104+
dirWithFile.toFile().deleteOnExit();
105+
// create file in sub-dir b, name or conter are irrelevant
106+
Path file = Files.createTempFile(dirWithFile.resolve("file"), "", "");
107+
file.toFile().deleteOnExit();
108+
109+
// create a test container
110+
CreateContainerResponse container = dockerClient.createContainerCmd("progrium/busybox:latest")
111+
.withCmd("/bin/sh", "-c", "while true; do sleep 9999; done")
112+
.exec();
113+
// start the container
114+
dockerClient.startContainerCmd(container.getId()).exec();
115+
// copy data from local dir to container
116+
dockerClient.copyArchiveToContainerCmd(container.getId())
117+
.withHostResource(localDir.toString())
118+
.exec();
119+
}
93120

94121
}

0 commit comments

Comments
 (0)