Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-28862] Optimize artifact archiving
  • Loading branch information
olivergondza committed Jun 18, 2015
1 parent 2a00036 commit 8650e1d
Showing 1 changed file with 8 additions and 16 deletions.
Expand Up @@ -30,9 +30,11 @@

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
Expand Down Expand Up @@ -60,30 +62,20 @@

final class ZipStorage extends VirtualFile {

// JarDriver is a ZipDriver that uses UTF-8 for entry names
private static final TArchiveDetector DETECTOR = new TArchiveDetector("zip", new JarDriver(IOPoolLocator.SINGLETON));

static VirtualFile root(File archive) {
return new ZipStorage(archive, "");
}

// TODO support updating entries
// TODO support updating entries. Hint: e4cf3284f14c919fb6bd95bfb147180569500623
static void archive(File archive, FilePath workspace, Launcher launcher, BuildListener listener, Map<String,String> artifacts) throws IOException, InterruptedException {
// Use temporary file for writing, rename when done
File tempArchive = new File(archive.getAbsolutePath() + ".writing.zip");

TFile zip = new TFile(tempArchive, DETECTOR);
zip.mkdir(); // Create new archive file
for (Entry<String, String> afs: artifacts.entrySet()) {
FilePath src = workspace.child(afs.getKey());
TFile dst = new TFile(zip, afs.getValue(), TArchiveDetector.NULL);
if (src.isDirectory()) {
dst.mkdirs();
} else {
TFile.cp(src.read(), dst);
}
OutputStream os = new FileOutputStream(tempArchive);
try {
workspace.zip(os, new FilePath.ExplicitlySpecifiedDirScanner(artifacts));
} finally {
os.close();
}
TVFS.umount(zip);
tempArchive.renameTo(archive);
}

Expand Down

0 comments on commit 8650e1d

Please sign in to comment.