From 14ff055f6ed33ca71bee4c9340f18cfa9d1248bc Mon Sep 17 00:00:00 2001 From: Olivier Theriault Date: Tue, 13 Oct 2020 11:06:47 -0400 Subject: [PATCH] GH-1121 Add POSIX config for long file name support for tar archives --- .../web/controller/ProjectGenerationController.java | 4 +++- .../ProjectGenerationControllerIntegrationTests.java | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/initializr-web/src/main/java/io/spring/initializr/web/controller/ProjectGenerationController.java b/initializr-web/src/main/java/io/spring/initializr/web/controller/ProjectGenerationController.java index 4cb51cfb31..8d521570fd 100644 --- a/initializr-web/src/main/java/io/spring/initializr/web/controller/ProjectGenerationController.java +++ b/initializr-web/src/main/java/io/spring/initializr/web/controller/ProjectGenerationController.java @@ -141,7 +141,9 @@ public ResponseEntity springTgz(R request) throws IOException { private TarArchiveOutputStream createTarArchiveOutputStream(OutputStream output) { try { - return new TarArchiveOutputStream(new GzipCompressorOutputStream(output)); + final TarArchiveOutputStream taos = new TarArchiveOutputStream(new GzipCompressorOutputStream(output)); + taos.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX); + return taos; } catch (IOException ex) { throw new IllegalStateException(ex); diff --git a/initializr-web/src/test/java/io/spring/initializr/web/controller/ProjectGenerationControllerIntegrationTests.java b/initializr-web/src/test/java/io/spring/initializr/web/controller/ProjectGenerationControllerIntegrationTests.java index dd40484d6c..6c1183fc47 100755 --- a/initializr-web/src/test/java/io/spring/initializr/web/controller/ProjectGenerationControllerIntegrationTests.java +++ b/initializr-web/src/test/java/io/spring/initializr/web/controller/ProjectGenerationControllerIntegrationTests.java @@ -65,6 +65,15 @@ void simpleTgzProject() { assertThat(project).mavenBuild().hasDependenciesSize(2).hasDependency("org.acme", "foo", "1.3.5"); } + @Test + void tgzProjectWithLongFilenames() { + String queryParams = "name=spring-boot-service&dependencies=org.acme:foo&artifactId=spring-boot-service" + + "&groupId=com.spring.boot.service&baseDir=spring-boot-service"; + + ResponseEntity entity = downloadArchive("/starter.tgz?" + queryParams); + assertArchiveResponseHeaders(entity, MediaType.valueOf("application/x-compress"), "spring-boot-service.tar.gz"); + } + private void assertArchiveResponseHeaders(ResponseEntity entity, MediaType contentType, String fileName) { assertThat(entity.getHeaders().getContentType()).isEqualTo(contentType); assertThat(entity.getHeaders().getContentDisposition()).isNotNull();