Add support for long fine names for tar archives

See gh-1139
This commit is contained in:
Olivier Theriault
2020-10-13 11:06:47 -04:00
committed by Stephane Nicoll
parent d878e89abc
commit 249b260774
2 changed files with 12 additions and 1 deletions

View File

@@ -141,7 +141,9 @@ public abstract class ProjectGenerationController<R extends ProjectRequest> {
private TarArchiveOutputStream createTarArchiveOutputStream(OutputStream output) { private TarArchiveOutputStream createTarArchiveOutputStream(OutputStream output) {
try { 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) { catch (IOException ex) {
throw new IllegalStateException(ex); throw new IllegalStateException(ex);

View File

@@ -65,6 +65,15 @@ class ProjectGenerationControllerIntegrationTests extends AbstractInitializrCont
assertThat(project).mavenBuild().hasDependenciesSize(2).hasDependency("org.acme", "foo", "1.3.5"); 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<byte[]> entity = downloadArchive("/starter.tgz?" + queryParams);
assertArchiveResponseHeaders(entity, MediaType.valueOf("application/x-compress"), "spring-boot-service.tar.gz");
}
private void assertArchiveResponseHeaders(ResponseEntity<byte[]> entity, MediaType contentType, String fileName) { private void assertArchiveResponseHeaders(ResponseEntity<byte[]> entity, MediaType contentType, String fileName) {
assertThat(entity.getHeaders().getContentType()).isEqualTo(contentType); assertThat(entity.getHeaders().getContentType()).isEqualTo(contentType);
assertThat(entity.getHeaders().getContentDisposition()).isNotNull(); assertThat(entity.getHeaders().getContentDisposition()).isNotNull();