Skip to content

Commit

Permalink
Always copy to "/" (root). Fixes #1954
Browse files Browse the repository at this point in the history
  • Loading branch information
bsideup committed Oct 6, 2019
1 parent 52420d8 commit 93c4c47
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1154,16 +1154,13 @@ public void copyFileToContainer(Transferable transferable, String containerPath)
) {
tarArchive.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);

int lastSlashIndex = StringUtils.removeEnd(containerPath, "/").lastIndexOf("/");
String extractArchiveTo = containerPath.substring(0, lastSlashIndex + 1);
String pathInArchive = containerPath.substring(lastSlashIndex + 1);
transferable.transferTo(tarArchive, pathInArchive);
transferable.transferTo(tarArchive, containerPath);
tarArchive.finish();

dockerClient
.copyArchiveToContainerCmd(containerId)
.withTarInputStream(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()))
.withRemotePath(extractArchiveTo)
.withRemotePath("/")
.exec();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,18 @@ public void shouldUseCopyOnlyWithReadOnlyClasspathResources() {
assertFalse("uses mount for read-only with Selinux", copyMap.containsValue("/readOnlyShared"));
assertFalse("uses mount for read-write", copyMap.containsValue("/readWrite"));
}

@Test
public void shouldCreateFoldersStructureWithCopy() throws Exception {
String resource = "/test_copy_to_container.txt";
try (
GenericContainer container = new GenericContainer<>()
.withCommand("sleep", "3000")
.withClasspathResourceMapping(resource, "/a/b/c/file", BindMode.READ_ONLY)
) {
container.start();
String filesList = container.execInContainer("ls", "/a/b/c/").getStdout();
assertTrue("file list contains the file", filesList.contains("file"));
}
}
}

0 comments on commit 93c4c47

Please sign in to comment.