Skip to content
Permalink
Browse files

[FIXED JENKINS-27522] Archive artifacts with non-ascii chars in path

  • Loading branch information...
olivergondza committed Mar 23, 2015
1 parent 9c149ee commit 74c1a8cc5490c763134bc2060fdd7dfea3b5d6c5
@@ -35,6 +35,7 @@
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Map;
@@ -52,11 +53,16 @@
import de.schlichtherle.truezip.file.TArchiveDetector;
import de.schlichtherle.truezip.file.TFile;
import de.schlichtherle.truezip.file.TVFS;
import de.schlichtherle.truezip.fs.archive.zip.JarDriver;
import de.schlichtherle.truezip.socket.sl.IOPoolLocator;
import de.schlichtherle.truezip.zip.ZipEntry;
import de.schlichtherle.truezip.zip.ZipFile;

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, "");
}
@@ -66,7 +72,7 @@ static void archive(File archive, FilePath workspace, Launcher launcher, BuildLi
// Use temporary file for writing, rename when done
File tempArchive = new File(archive.getAbsolutePath() + ".writing.zip");

TFile zip = new TFile(tempArchive, new TArchiveDetector("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());
@@ -47,6 +47,7 @@
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;

import org.junit.Before;
@@ -307,6 +308,31 @@ public void supporMissingArchiveFile() throws Exception {
}
}

@Test
public void specialCaracters() throws Exception {
String dirname = "Příliš_žluťoučký_kůň";
String filename = "úpěl_ďábelské_ódy";

File subdir = new File(content, dirname);
subdir.mkdirs();

FileUtils.writeStringToFile(new File(subdir, filename), "content");

String fullname = dirname + "/" + filename;
archive(Collections.singletonMap(fullname, fullname));

testSpecialCaracters(canonical);
testSpecialCaracters(zs);
}

private void testSpecialCaracters(VirtualFile vf) throws Exception {
assertEquals(1, vf.list().length);
VirtualFile subdir = vf.child("Příliš_žluťoučký_kůň");
assertTrue(subdir.exists());
assertEquals(1, subdir.list().length);
assertTrue(subdir.child("úpěl_ďábelské_ódy").exists());
}

private void archive(Map<String, String> artifacts) throws Exception {
BuildListener l = new StreamBuildListener(System.out, Charset.defaultCharset());
ZipStorage.archive(archive, new FilePath(content), new Launcher.LocalLauncher(l), l, artifacts);

0 comments on commit 74c1a8c

Please sign in to comment.
You can’t perform that action at this time.