Skip to content

Commit

Permalink
Fix #680: Ensure that tar entries for Dockerfile builder do not have …
Browse files Browse the repository at this point in the history
…trailing slashes
  • Loading branch information
rnorth committed Jul 29, 2018
1 parent 8907226 commit 5530fad
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,14 @@ private void recursiveTar(String entryFilename, String rootPath, String itemPath
final File sourceRootFile = new File(rootPath).getCanonicalFile(); // e.g. /foo
final String relativePathToSourceFile = sourceRootFile.toPath().relativize(sourceFile.toPath()).toFile().toString(); // e.g. /bar/baz

final TarArchiveEntry tarEntry = new TarArchiveEntry(sourceFile, entryFilename + "/" + relativePathToSourceFile); // entry filename e.g. /xyz/bar/baz
final String tarEntryFilename;
if (relativePathToSourceFile.isEmpty()) {
tarEntryFilename = entryFilename; // entry filename e.g. xyz => xyz
} else {
tarEntryFilename = entryFilename + "/" + relativePathToSourceFile; // entry filename e.g. /xyz/bar/baz => /foo/bar/baz
}

final TarArchiveEntry tarEntry = new TarArchiveEntry(sourceFile, tarEntryFilename);

// TarArchiveEntry automatically sets the mode for file/directory, but we can update to ensure that the mode is set exactly (inc executable bits)
tarEntry.setMode(getUnixFileMode(itemPath));
Expand Down

0 comments on commit 5530fad

Please sign in to comment.