Skip to content
This repository has been archived by the owner on Mar 21, 2022. It is now read-only.

Fix error when exporting image tar file #338

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
13 changes: 12 additions & 1 deletion src/main/java/com/spotify/docker/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,19 @@ public static void saveImage(DockerClient docker, String imageName,
throws DockerException, IOException, InterruptedException {
log.info(String.format("Save docker image %s to %s.",
imageName, tarArchivePath.toAbsolutePath()));
final Path archiveParentDir = tarArchivePath.getParent().toAbsolutePath();
if (Files.exists(archiveParentDir)) {
if (!Files.isDirectory(archiveParentDir)) {
throw new IOException(
"The provided path for docker image tar archive export exists, "
+ "but is not a directory: " + archiveParentDir.toString());
}
} else {
Files.createDirectories(archiveParentDir);
}
final InputStream is = docker.save(imageName);
java.nio.file.Files.copy(is, tarArchivePath, StandardCopyOption.REPLACE_EXISTING);
java.nio.file.Files.copy(is, tarArchivePath.toAbsolutePath(),
StandardCopyOption.REPLACE_EXISTING);
}

public static void writeImageInfoFile(final DockerBuildInformation buildInfo,
Expand Down