Skip to content

Commit 86eebf4

Browse files
authored
Fixes long file names. (#92)
1 parent 04116c9 commit 86eebf4

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ All notable changes to this project will be documented in this file.
2525
- Cannot use private base image ([#68](https://github.com/google/jib/pull/68))
2626
- Building applications with no resources ([#73](https://github.com/google/jib/pull/73))
2727
- Pushing to registries like Docker Hub and ACR ([#75](https://github.com/google/jib/issues/75))
28+
- Cannot build with files having long file names (> 100 chars) ([#91](https://github.com/google/jib/issues/91))

jib-core/src/main/java/com/google/cloud/tools/jib/tar/TarStreamBuilder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ private static void writeEntriesAsTarArchive(
4141
List<TarArchiveEntry> entries, OutputStream tarByteStream) throws IOException {
4242
try (TarArchiveOutputStream tarArchiveOutputStream =
4343
new TarArchiveOutputStream(tarByteStream)) {
44+
// Enables PAX extended headers to support long file names.
45+
tarArchiveOutputStream.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
46+
4447
for (TarArchiveEntry entry : entries) {
4548
tarArchiveOutputStream.putArchiveEntry(entry);
4649
if (entry.isFile()) {

jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ public void setUp() throws IOException, URISyntaxException {
6060
new TarArchiveEntry(fileA.toFile(), "some/path/to/resourceFileA"));
6161
testTarStreamBuilder.addEntry(new TarArchiveEntry(fileB.toFile(), "crepecake"));
6262
testTarStreamBuilder.addEntry(new TarArchiveEntry(directoryA.toFile(), "some/path/to"));
63+
testTarStreamBuilder.addEntry(
64+
new TarArchiveEntry(
65+
fileA.toFile(),
66+
"some/really/long/path/that/exceeds/100/characters/abcdefghijklmnopqrstuvwxyz0123456789012345678901234567890"));
6367
}
6468

6569
@Test
@@ -119,6 +123,15 @@ private void verifyTarArchive(TarArchiveInputStream tarArchiveInputStream) throw
119123
TarArchiveEntry headerDirectoryA = tarArchiveInputStream.getNextTarEntry();
120124
Assert.assertEquals("some/path/to/", headerDirectoryA.getName());
121125

126+
// Verifies the long file was archived correctly.
127+
TarArchiveEntry headerFileALong = tarArchiveInputStream.getNextTarEntry();
128+
Assert.assertEquals(
129+
"some/really/long/path/that/exceeds/100/characters/abcdefghijklmnopqrstuvwxyz0123456789012345678901234567890",
130+
headerFileALong.getName());
131+
String fileALongString =
132+
CharStreams.toString(new InputStreamReader(tarArchiveInputStream, StandardCharsets.UTF_8));
133+
Assert.assertEquals(expectedFileAString, fileALongString);
134+
122135
Assert.assertNull(tarArchiveInputStream.getNextTarEntry());
123136
}
124137
}

0 commit comments

Comments
 (0)