提交 793b6826 编写于 作者: J Jesse Glick

[FIXED JENKINS-19947] Restore historical undocumented behavior of a top-level entry in a ZIP.

Noting that various DirScanner implementations handle this inconsistently.
上级 0099e0d9
......@@ -58,6 +58,9 @@ Upcoming changes</a>
<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
......
......@@ -392,7 +392,7 @@ public final class FilePath implements Serializable {
*
* @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
*/
......
......@@ -341,7 +341,14 @@ public final class DirectoryBrowserSupport implements HttpResponse {
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 @@ public abstract class DirScanner implements Serializable {
/**
* 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 abstract class DirScanner implements Serializable {
}
/**
* 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 abstract class DirScanner implements Serializable {
/**
* 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 class DirectoryBrowserSupportTest {
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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册