Skip to content

Commit 55774b8

Browse files
idodeclareVladimir Kotal
authored andcommitted
Fix #2997 : redirect (conditionally) before writing partially
1 parent a984fba commit 55774b8

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

opengrok-web/src/main/webapp/list.jsp

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ org.opengrok.web.DirectoryListing,
5656
org.opengrok.indexer.web.SearchHelper"
5757
%>
5858
<%
59+
final String DUMMY_REVISION = "unknown";
60+
5961
{
6062
// need to set it here since requesting parameters
6163
if (request.getCharacterEncoding() == null) {
@@ -65,6 +67,30 @@ org.opengrok.indexer.web.SearchHelper"
6567
PageConfig cfg = PageConfig.get(request);
6668
cfg.checkSourceRootExistence();
6769
70+
String rev = cfg.getRequestedRevision();
71+
if (!cfg.isDir() && rev.length() == 0) {
72+
/*
73+
* Get the latest revision and redirect so that the revision number
74+
* appears in the URL.
75+
*/
76+
String location = cfg.getRevisionLocation(cfg.getLatestRevision());
77+
if (location != null) {
78+
response.sendRedirect(location);
79+
return;
80+
}
81+
if (!cfg.getEnv().isGenerateHtml()) {
82+
/*
83+
* Economy mode is on and failed to get the last revision
84+
* (presumably running with history turned off). Use dummy
85+
* revision string so that xref can be generated from the resource
86+
* file directly.
87+
*/
88+
location = cfg.getRevisionLocation(DUMMY_REVISION);
89+
response.sendRedirect(location);
90+
return;
91+
}
92+
}
93+
6894
Annotation annotation = cfg.getAnnotation();
6995
if (annotation != null) {
7096
int r = annotation.getWidestRevision();
@@ -90,7 +116,6 @@ document.pageReady.push(function() { pageReadyList();});
90116
PageConfig cfg = PageConfig.get(request);
91117
String rev = cfg.getRequestedRevision();
92118
Project project = cfg.getProject();
93-
final String DUMMY_REVISION = "unknown";
94119
95120
String navigateWindowEnabled = project != null ? Boolean.toString(
96121
project.isNavigateWindowEnabled()) : "false";
@@ -186,7 +211,7 @@ document.pageReady.push(function() { pageReadyList();});
186211
}
187212
} else if (rev.length() != 0) {
188213
// requesting a revision
189-
File xrefFile = null;
214+
File xrefFile;
190215
if (cfg.isLatestRevision(rev) &&
191216
(xrefFile = cfg.findDataFile()) != null) {
192217
if (cfg.annotate()) {
@@ -396,25 +421,8 @@ Click <a href="<%= rawPath %>">download <%= basename %></a><%
396421
}
397422
} else {
398423
// requesting cross referenced file
399-
File xrefFile = null;
400-
401-
// Get the latest revision and redirect so that the revision number appears in the URL.
402-
String location = cfg.getRevisionLocation(cfg.getLatestRevision());
403-
if (location != null) {
404-
response.sendRedirect(location);
405-
return;
406-
} else {
407-
if (!cfg.getEnv().isGenerateHtml()) {
408-
// Economy mode is on and failed to get the last revision (presumably running with history turned off).
409-
// Use dummy revision string so that xref can be generated from the resource file directly.
410-
location = cfg.getRevisionLocation(DUMMY_REVISION);
411-
response.sendRedirect(location);
412-
return;
413-
}
414-
415-
xrefFile = cfg.findDataFile();
416-
}
417424
425+
File xrefFile = cfg.findDataFile();
418426
if (xrefFile != null) {
419427
%>
420428
<div id="src" data-navigate-window-enabled="<%= navigateWindowEnabled %>">

0 commit comments

Comments
 (0)