|
43 | 43 | import java.util.Arrays;
|
44 | 44 | import java.util.Collections;
|
45 | 45 | import java.util.Comparator;
|
| 46 | +import java.util.Date; |
46 | 47 | import java.util.EnumSet;
|
47 | 48 | import java.util.List;
|
48 | 49 | import java.util.Objects;
|
|
61 | 62 | import jakarta.servlet.http.HttpServletRequest;
|
62 | 63 | import jakarta.servlet.http.HttpServletResponse;
|
63 | 64 | import jakarta.ws.rs.core.HttpHeaders;
|
| 65 | +import org.apache.lucene.document.DateTools; |
64 | 66 | import org.apache.lucene.document.Document;
|
65 | 67 | import org.jetbrains.annotations.Nullable;
|
66 | 68 | import org.opengrok.indexer.Info;
|
@@ -1342,11 +1344,24 @@ private String getLastRevFromHistory() {
|
1342 | 1344 | return he.getRevision();
|
1343 | 1345 | }
|
1344 | 1346 |
|
| 1347 | + /** |
| 1348 | + * 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. |
| 1351 | + */ |
1345 | 1352 | @Nullable
|
1346 | 1353 | private String getLastRevFromIndex() {
|
1347 | 1354 | Document doc = null;
|
1348 | 1355 | try {
|
1349 | 1356 | doc = IndexDatabase.getDocument(getResourceFile());
|
| 1357 | + if (doc != null) { |
| 1358 | + Date docDate = DateTools.stringToDate(doc.get(QueryBuilder.DATE)); |
| 1359 | + Date fileDate = new Date(getResourceFile().lastModified()); |
| 1360 | + if (docDate.compareTo(fileDate) < 0) { |
| 1361 | + LOGGER.log(Level.FINER, "document for '{0}' is out of sync", getResourceFile()); |
| 1362 | + return null; |
| 1363 | + } |
| 1364 | + } |
1350 | 1365 | } catch (Exception e) {
|
1351 | 1366 | LOGGER.log(Level.WARNING, String.format("cannot get document for %s", path), e);
|
1352 | 1367 | }
|
|
0 commit comments