Fixes copyArchiveToContainerCmdImpl fail when hostResource has an emtty dir which gets added as last entry to tar #574
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a simple fix for CopyArchiveToContainerCmdImpl which fails with com.github.dockerjava.api.exception.BadRequestException: Unable to perform tar on host resource /path/to/resource, when the resourceHost is a dir that contains an empty dir which will be added as the last entry to the generated .tar file.
Steps to reproduce
Name the dirs in the local dir exactly as shown above (preserve names a and b, the file name or content is irrelevant).
Then, the output will be:
com.github.dockerjava.api.exception.BadRequestException: Unable to perform tar on host resource /path/to/resource
In oder to generate the tar file, all files under the local dir must be added to the tarArchiveOutputStream as tarArchiveEntries. The exception happens when the last entry added to the tarArchiveOutputStream is an empty dir.
Notice
In order to view the order with which the files and folders are added to the tarArchiveOutputStream you may add print messages to: com.github.dockerjava.core.util.TarDirWalker class. Specifically, to methods: preVisitDirectory(), visitFile(), e.g.
If in any case, the empty folder is not the last entry added to tarArchiveOutputStream the exception won't be reproduced.
This change is