Skip to content

Commit

Permalink
[FIXED JENKINS-19947] Restore historical undocumented behavior of a t…
Browse files Browse the repository at this point in the history
…op-level entry in a ZIP.

Noting that various DirScanner implementations handle this inconsistently.
  • Loading branch information
jglick committed Oct 9, 2013
1 parent 0099e0d commit 793b682
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -58,6 +58,9 @@
<li class=bug>
RuntimeException if you try to save a config with a choice parameter that has no choices.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-18434">issue 18434</a>)
<li class=bug>
1.534 made ZIP downloads of artifacts work again, but missing a base directory inside the ZIP.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-19947">issue 19947</a>)
<li class='major bug'>
Upgrade Trilead SSH client library to version that does not cause connection loss when
there is a lot of logging on the build slave and the performance improvements in
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/FilePath.java
Expand Up @@ -392,7 +392,7 @@ public void createZipArchive(OutputStream os, final String glob) throws IOExcept
*
* @param glob
* Ant style glob, like "**&#x2F;*.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 793b682

Please sign in to comment.