Skip to content

Commit df71298

Browse files
author
Vladimir Kotal
committed
better check
1 parent 8ff8eec commit df71298

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

opengrok-web/src/main/java/org/opengrok/web/PageConfig.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.nio.charset.StandardCharsets;
4040
import java.nio.file.Paths;
4141
import java.security.InvalidParameterException;
42+
import java.text.ParseException;
4243
import java.util.ArrayList;
4344
import java.util.Arrays;
4445
import java.util.Collections;
@@ -1346,31 +1347,39 @@ private String getLastRevFromHistory() {
13461347

13471348
/**
13481349
* Retrieve last revision from the document matching the resource file (if any).
1349-
* @return last revision or {@code null} if the document cannot be found or is out of sync
1350-
* w.r.t. last modified time of the file.
1350+
* @return last revision or {@code null} if the document cannot be found, is out of sync
1351+
* w.r.t. last modified time of the file or the last commit ID is not stored in the document.
13511352
*/
13521353
@Nullable
13531354
private String getLastRevFromIndex() {
13541355
Document doc = null;
13551356
try {
13561357
doc = IndexDatabase.getDocument(getResourceFile());
1357-
if (doc != null) {
1358-
Date docDate = DateTools.stringToDate(doc.get(QueryBuilder.DATE));
1358+
} catch (Exception e) {
1359+
LOGGER.log(Level.WARNING, String.format("cannot get document for %s", path), e);
1360+
}
1361+
1362+
String lastRev = null;
1363+
if (doc != null) {
1364+
// There is no point of checking the date if the LASTREV field is not present.
1365+
lastRev = doc.get(QueryBuilder.LASTREV);
1366+
if (lastRev != null) {
1367+
Date docDate;
1368+
try {
1369+
docDate = DateTools.stringToDate(doc.get(QueryBuilder.DATE));
1370+
} catch (ParseException e) {
1371+
LOGGER.log(Level.WARNING, String.format("cannot get date from the document %s", doc), e);
1372+
return null;
1373+
}
13591374
Date fileDate = new Date(getResourceFile().lastModified());
13601375
if (docDate.compareTo(fileDate) < 0) {
13611376
LOGGER.log(Level.FINER, "document for '{0}' is out of sync", getResourceFile());
13621377
return null;
13631378
}
13641379
}
1365-
} catch (Exception e) {
1366-
LOGGER.log(Level.WARNING, String.format("cannot get document for %s", path), e);
13671380
}
13681381

1369-
if (doc != null) {
1370-
return doc.get(QueryBuilder.LASTREV);
1371-
}
1372-
1373-
return null;
1382+
return lastRev;
13741383
}
13751384

13761385
/**

0 commit comments

Comments
 (0)