Skip to content
Permalink
Browse files

[FIXED JENKINS-19947] Restore historical undocumented behavior of a t…

…op-level entry in a ZIP.

Noting that various DirScanner implementations handle this inconsistently.

(cherry picked from commit 793b682)

Conflicts:
	changelog.html
  • Loading branch information...
jglick authored and olivergondza committed Oct 9, 2013
1 parent 0c9503a commit 3695e614ed51c344bcc7deafaee44b11f7d1151d
@@ -391,7 +391,7 @@ public void createZipArchive(OutputStream os, final String glob) throws IOExcept
*
* @param glob
* Ant style glob, like "**/*.xml". If empty or null, this method
* works like {@link #createZipArchive(OutputStream)}
* works like {@link #createZipArchive(OutputStream)}, inserting a top-level directory into the ZIP.
*
* @since 1.315
*/
@@ -341,7 +341,14 @@ private static String createBackRef(int times) {
private static void zip(OutputStream outputStream, VirtualFile dir, String glob) throws IOException {
ZipOutputStream zos = new ZipOutputStream(outputStream);
for (String n : dir.list(glob.length() == 0 ? "**" : glob)) {
ZipEntry e = new ZipEntry(n);
String relativePath;
if (glob.length() == 0) {
// JENKINS-19947: traditional behavior is to prepend the directory name
relativePath = dir.getName() + '/' + n;
} else {
relativePath = n;
}
ZipEntry e = new ZipEntry(relativePath);
VirtualFile f = dir.child(n);
e.setTime(f.lastModified());
zos.putNextEntry(e);
@@ -51,6 +51,9 @@ protected final void scanSingle(File f, String relative, FileVisitor visitor) th

/**
* Scans everything recursively.
* <p>Note that all file paths are prefixed by the name of the root directory.
* For example, when scanning a directory {@code /tmp/dir} containing a file {@code file},
* the {@code relativePath} sent to the {@link FileVisitor} will be {@code dir/file}.
*/
public static class Full extends DirScanner {
private void scan(File f, String path, FileVisitor visitor) throws IOException {
@@ -71,7 +74,8 @@ public void scan(File dir, FileVisitor visitor) throws IOException {
}

/**
* Scans by filtering things out from {@link FileFilter}
* Scans by filtering things out from {@link FileFilter}.
* <p>An initial basename is prepended as with {@link Full}.
*/
public static class Filter extends Full {
private final FileFilter filter;
@@ -90,6 +94,10 @@ public void scan(File dir, FileVisitor visitor) throws IOException {

/**
* Scans by using Ant GLOB syntax.
* <p>An initial basename is prepended as with {@link Full} <strong>if the includes and excludes are blank</strong>.
* Otherwise there is no prepended path. So for example when scanning a directory {@code /tmp/dir} containing a file {@code file},
* the {@code relativePath} sent to the {@link FileVisitor} will be {@code dir/file} if {@code includes} is blank
* but {@code file} if it is {@code **}. (This anomaly is historical.)
*/
public static class Glob extends DirScanner {
private final String includes, excludes;
@@ -159,7 +159,7 @@ public void zipDownload() throws Exception {

ZipFile readzip = new ZipFile(zipfile);

InputStream is = readzip.getInputStream(readzip.getEntry("artifact.out"));
InputStream is = readzip.getInputStream(readzip.getEntry("archive/artifact.out"));

// ZipException in case of JENKINS-19752
assertFalse("Downloaded zip file must not be empty", is.read() == -1);

0 comments on commit 3695e61

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