Bugfix for long filenames in tar (#1552)

Fixes errors with long file names in tar archives. This may arise with hg repositories with deep directories.
This commit is contained in:
René Pfeuffer
2021-02-18 16:30:35 +01:00
committed by GitHub
parent d8427ed4ed
commit d0df8977ef
14 changed files with 316 additions and 135 deletions

View File

@@ -42,6 +42,7 @@ import java.nio.file.StandardCopyOption;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static sonia.scm.util.Archives.createTarInputStream;
class GitBundleCommandTest {
@@ -94,7 +95,7 @@ class GitBundleCommandTest {
}
private void assertStreamContainsContent(ByteArrayOutputStream baos, String content) throws IOException {
TarArchiveInputStream tais = new TarArchiveInputStream(new BufferedInputStream(new ByteArrayInputStream(baos.toByteArray())));
TarArchiveInputStream tais = createTarInputStream(new BufferedInputStream(new ByteArrayInputStream(baos.toByteArray())));
tais.getNextEntry();
byte[] result = IOUtils.toByteArray(tais);

View File

@@ -30,8 +30,8 @@ import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import sonia.scm.util.Archives;
import javax.annotation.Nonnull;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
@@ -82,9 +82,10 @@ class GitUnbundleCommandTest extends AbstractGitCommandTestBase {
private UnbundleCommandRequest createUnbundleCommandRequestForFile(Path temp, String filePath, String fileContent) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
TarArchiveOutputStream taos = new TarArchiveOutputStream(baos);
TarArchiveOutputStream taos = Archives.createTarOutputStream(baos);
addEntry(taos, filePath, fileContent);
taos.finish();
taos.close();
when(gitContext.getDirectory()).thenReturn(temp.toFile());
ByteSource byteSource = ByteSource.wrap(baos.toByteArray());