Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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 Nov 2, 2013
1 parent 0c9503a commit 3695e61
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/FilePath.java
Expand Up @@ -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
*/
Expand Down
9 changes: 8 additions & 1 deletion core/src/main/java/hudson/model/DirectoryBrowserSupport.java
Expand Up @@ -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);
Expand Down
10 changes: 9 additions & 1 deletion core/src/main/java/hudson/util/DirScanner.java
Expand Up @@ -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 {
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Expand Up @@ -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);
Expand Down

0 comments on commit 3695e61

Please sign in to comment.