Skip to content

Commit 8ff8eec

Browse files
author
Vladimir Kotal
committed
compare document date to file date
fixes #3510
1 parent 6364b31 commit 8ff8eec

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.util.Arrays;
4444
import java.util.Collections;
4545
import java.util.Comparator;
46+
import java.util.Date;
4647
import java.util.EnumSet;
4748
import java.util.List;
4849
import java.util.Objects;
@@ -61,6 +62,7 @@
6162
import jakarta.servlet.http.HttpServletRequest;
6263
import jakarta.servlet.http.HttpServletResponse;
6364
import jakarta.ws.rs.core.HttpHeaders;
65+
import org.apache.lucene.document.DateTools;
6466
import org.apache.lucene.document.Document;
6567
import org.jetbrains.annotations.Nullable;
6668
import org.opengrok.indexer.Info;
@@ -1342,11 +1344,24 @@ private String getLastRevFromHistory() {
13421344
return he.getRevision();
13431345
}
13441346

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+
*/
13451352
@Nullable
13461353
private String getLastRevFromIndex() {
13471354
Document doc = null;
13481355
try {
13491356
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+
}
13501365
} catch (Exception e) {
13511366
LOGGER.log(Level.WARNING, String.format("cannot get document for %s", path), e);
13521367
}

0 commit comments

Comments
 (0)