Skip to content
Permalink
Browse files
[FIXED JENKINS-10629] Unbroke stream with new tar implementation.
Causes bytes lost and truncated tar archive.
TarBuffer not used in TarArchiveOutputStream.

(cherry picked from commit 3e187a0)
  • Loading branch information
KostyaSha authored and olivergondza committed Oct 28, 2015
1 parent 2b63fea commit fd1e392fd4cb9d9feade9da7540c00921d32d816
Showing with 32 additions and 9 deletions.
  1. +1 −9 core/src/main/java/hudson/util/io/TarArchiver.java
  2. +31 −0 core/src/test/java/hudson/FilePathTest.java
@@ -52,15 +52,7 @@
private final TarArchiveOutputStream tar;

TarArchiver(OutputStream out) {
tar = new TarArchiveOutputStream(new BufferedOutputStream(out) {
// TarOutputStream uses TarBuffer internally,
// which flushes the stream for each block. this creates unnecessary
// data stream fragmentation, and flush request to a remote, which slows things down.
@Override
public void flush() throws IOException {
// so don't do anything in flush
}
});
tar = new TarArchiveOutputStream(out);
tar.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_STAR);
tar.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
}
@@ -659,4 +659,35 @@ private InputStream someZippedContent() throws IOException {
// test conflict subdir
src.moveAllChildrenTo(dst);
}

@Issue("JENKINS-10629")
@Test
public void testEOFbrokenFlush() throws IOException, InterruptedException {
final File srcFolder = temp.newFolder("src");
// simulate magic structure with magic sizes:
// |- dir/pom.xml (2049)
// |- pom.xml (2049)
// \- small.tar (1537)
final File smallTar = new File(srcFolder, "small.tar");
givenSomeContentInFile(smallTar, 1537);
final File dir = new File(srcFolder, "dir");
dir.mkdirs();
final File pomFile = new File(dir, "pom.xml");
givenSomeContentInFile(pomFile, 2049);
FileUtils.copyFileToDirectory(pomFile, srcFolder);

final File archive = temp.newFile("archive.tar");

// Compress archive
final FilePath tmpDirPath = new FilePath(srcFolder);
int tarred = tmpDirPath.tar(new FileOutputStream(archive), "**");
assertEquals("One file should have been compressed", 3, tarred);

// Decompress
final File dstFolder = temp.newFolder("dst");
dstFolder.mkdirs();
FilePath outDir = new FilePath(dstFolder);
// and now fail when flush is bad!
tmpDirPath.child("../" + archive.getName()).untar(outDir, TarCompression.NONE);
}
}

0 comments on commit fd1e392

Please sign in to comment.