Skip to content

Commit

Permalink
[FIXED JENKINS-10629] Unbroke stream with new tar implementation.
Browse files Browse the repository at this point in the history
Causes bytes lost and truncated tar archive.
TarBuffer not used in TarArchiveOutputStream.
  • Loading branch information
KostyaSha committed Aug 24, 2015
1 parent 2ef2921 commit 3e187a0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
10 changes: 1 addition & 9 deletions core/src/main/java/hudson/util/io/TarArchiver.java
Expand Up @@ -52,15 +52,7 @@ final class TarArchiver extends Archiver {
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);
}
Expand Down
31 changes: 31 additions & 0 deletions core/src/test/java/hudson/FilePathTest.java
Expand Up @@ -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 3e187a0

Please sign in to comment.