From ddaed96036ebf82430e09ad62ff9f7a7dc828dfe Mon Sep 17 00:00:00 2001 From: James Moger Date: Wed, 23 Apr 2014 11:18:40 -0400 Subject: [PATCH] Fix subdirectory links in pages servlet (issue-411) --- releases.moxie | 4 +++- src/main/java/com/gitblit/servlet/PagesServlet.java | 11 +++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/releases.moxie b/releases.moxie index 8e183f74..53fc3ead 100644 --- a/releases.moxie +++ b/releases.moxie @@ -9,7 +9,8 @@ r23: { html: ~ text: ~ security: ~ - fixes: ~ + fixes: + - Fix subdirectory links in pages servlet (issue-411) changes: - improve French translation (pr-176) - simplify current plugin release detection and ignore the currentRelease registry field @@ -20,6 +21,7 @@ r23: { - James Moger - Julien Kirch - Ralph Hoffman + - Olivier Rouits } # diff --git a/src/main/java/com/gitblit/servlet/PagesServlet.java b/src/main/java/com/gitblit/servlet/PagesServlet.java index 74c1cb2d..5124b8ca 100644 --- a/src/main/java/com/gitblit/servlet/PagesServlet.java +++ b/src/main/java/com/gitblit/servlet/PagesServlet.java @@ -28,6 +28,7 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevTree; @@ -228,11 +229,17 @@ public class PagesServlet extends DaggerServlet { response.getWriter().append("pathmodesize"); response.getWriter().append(""); response.getWriter().append(""); - String pattern = "{0}{1}{2}"; + String pattern = "{1}{2}{3}"; final ByteFormat byteFormat = new ByteFormat(); List entries = JGitUtils.getFilesInPath(r, resource, commit); + if (!entries.isEmpty()) { + if (entries.get(0).path.indexOf('/') > -1) { + // we are in a subdirectory, add parent directory link + entries.add(0, new PathModel("..", resource + "/..", 0, FileMode.TREE.getBits(), null, null)); + } + } for (PathModel entry : entries) { - response.getWriter().append(MessageFormat.format(pattern, entry.name, JGitUtils.getPermissionsFromMode(entry.mode), byteFormat.format(entry.size))); + response.getWriter().append(MessageFormat.format(pattern, entry.path, entry.name, JGitUtils.getPermissionsFromMode(entry.mode), byteFormat.format(entry.size))); } response.getWriter().append(""); response.getWriter().append(""); -- 2.39.5