提交 ccdc285d 编写于 作者: K kohsuke

eliminated dupicate.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@4252 71c3de6d-444a-0410-be80-ed276b4c234a
上级 ef346ef2
...@@ -66,21 +66,12 @@ public final class DirectoryBrowserSupport { ...@@ -66,21 +66,12 @@ public final class DirectoryBrowserSupport {
* False to serve "index.html" * False to serve "index.html"
*/ */
public final void serveFile(StaplerRequest req, StaplerResponse rsp, FilePath root, String icon, boolean serveDirIndex) throws IOException, ServletException, InterruptedException { public final void serveFile(StaplerRequest req, StaplerResponse rsp, FilePath root, String icon, boolean serveDirIndex) throws IOException, ServletException, InterruptedException {
String pattern = req.getParameter("pattern");
if(pattern==null)
pattern = req.getParameter("path"); // compatibility with Hudson<1.129
if (pattern != null) {
servePattern(req, rsp, root, icon, pattern);
return;
}
String path = req.getRestOfPath(); String path = req.getRestOfPath();
if(path.length()==0) if(path.length()==0)
path = "/"; path = "/";
if(path.indexOf("..")!=-1 || path.length()<1) { if(path.indexOf("..")!=-1) {
// don't serve anything other than files in the artifacts dir // don't serve anything other than files in the artifacts dir
rsp.sendError(HttpServletResponse.SC_BAD_REQUEST); rsp.sendError(HttpServletResponse.SC_BAD_REQUEST);
return; return;
...@@ -88,6 +79,15 @@ public final class DirectoryBrowserSupport { ...@@ -88,6 +79,15 @@ public final class DirectoryBrowserSupport {
FilePath f = new FilePath(root,path.substring(1)); FilePath f = new FilePath(root,path.substring(1));
String pattern = req.getParameter("pattern");
if(pattern==null)
pattern = req.getParameter("path"); // compatibility with Hudson<1.129
if (pattern != null) {
servePattern(req, rsp, f, path, icon, pattern);
return;
}
boolean isFingerprint=false; boolean isFingerprint=false;
if(f.getName().equals("*fingerprint*")) { if(f.getName().equals("*fingerprint*")) {
f = f.getParent(); f = f.getParent();
...@@ -134,7 +134,7 @@ public final class DirectoryBrowserSupport { ...@@ -134,7 +134,7 @@ public final class DirectoryBrowserSupport {
} else { } else {
ContentInfo ci = f.act(new ContentInfo()); ContentInfo ci = f.act(new ContentInfo());
InputStream in = f.read(); InputStream in = f.read();
if (view) { if (view) {
// for binary files, provide the file name for download // for binary files, provide the file name for download
rsp.setHeader("Content-Disposition", "inline; filename=" + f.getName()); rsp.setHeader("Content-Disposition", "inline; filename=" + f.getName());
...@@ -142,7 +142,7 @@ public final class DirectoryBrowserSupport { ...@@ -142,7 +142,7 @@ public final class DirectoryBrowserSupport {
// pseudo file name to let the Stapler set text/plain // pseudo file name to let the Stapler set text/plain
rsp.serveFile(req, in, ci.lastModified, -1, ci.contentLength, "plain.txt"); rsp.serveFile(req, in, ci.lastModified, -1, ci.contentLength, "plain.txt");
} else { } else {
rsp.serveFile(req, in, ci.lastModified, -1, ci.contentLength, f.getName() ); rsp.serveFile(req, in, ci.lastModified, -1, ci.contentLength, f.getName() );
} }
in.close(); in.close();
...@@ -165,23 +165,14 @@ public final class DirectoryBrowserSupport { ...@@ -165,23 +165,14 @@ public final class DirectoryBrowserSupport {
/** /**
* Serves files matched by the pattern relativ to the current workspace directory. * Serves files matched by the pattern relativ to the current workspace directory.
*/ */
private void servePattern(StaplerRequest req, StaplerResponse rsp, FilePath root, String icon, final String pattern) throws IOException, ServletException, InterruptedException { private void servePattern(StaplerRequest req, StaplerResponse rsp, FilePath root, String path, String icon, String pattern) throws IOException, ServletException, InterruptedException {
String path = req.getRestOfPath(); if(new FilePath(root,pattern).exists()) {
if (path.length() > 0) {
// remove leading slash since the root path ends with a slash
path = path.substring(1);
}
// current workspace directory
FilePath curDir = new FilePath(root, path);
if(new FilePath(curDir,pattern).exists()) {
// this file/directory exists, so it's not a pattern // this file/directory exists, so it's not a pattern
rsp.sendRedirect2(pattern); rsp.sendRedirect2(pattern);
return; return;
} }
serveFileListing(req,path,root,icon,rsp,curDir.act(new PatternScanner(pattern)),pattern); serveFileListing(req,path,root,icon,rsp,root.act(new PatternScanner(pattern)),pattern);
} }
private static final class ContentInfo implements FileCallable<ContentInfo> { private static final class ContentInfo implements FileCallable<ContentInfo> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册