This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-indexer.git


The following commit(s) were added to refs/heads/master by this push:
     new 58cb577f Ignore a stored index timestamp that lies in the future
58cb577f is described below

commit 58cb577f9239b6bf436a5c65211e7c2e61db4d55
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Mon Nov 16 09:51:06 2026 +0100

    Ignore a stored index timestamp that lies in the future
    
    A local timestamp more than a day ahead of the clock no longer marks the
    index as up to date, so the update proceeds instead of skipping. The day
    of margin keeps publisher clock skew from forcing full downloads. With
    incrementalOnly and no usable chunk chain, such a run now reports
    unsuccessful instead of succeeding without fetching anything.
---
 .../maven/index/updater/DefaultIndexUpdater.java   |  7 +++++
 .../index/updater/DefaultIndexUpdaterTest.java     | 33 ++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git 
a/indexer-core/src/main/java/org/apache/maven/index/updater/DefaultIndexUpdater.java
 
b/indexer-core/src/main/java/org/apache/maven/index/updater/DefaultIndexUpdater.java
index cc11ced5..dcfc8b4f 100644
--- 
a/indexer-core/src/main/java/org/apache/maven/index/updater/DefaultIndexUpdater.java
+++ 
b/indexer-core/src/main/java/org/apache/maven/index/updater/DefaultIndexUpdater.java
@@ -46,6 +46,7 @@ import java.util.List;
 import java.util.Properties;
 import java.util.Set;
 import java.util.TimeZone;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.lucene.document.Document;
 import org.apache.lucene.index.DirectoryReader;
@@ -588,6 +589,12 @@ public class DefaultIndexUpdater implements IndexUpdater {
                 localTimestamp = getTimestamp(localProperties, 
IndexingContext.INDEX_TIMESTAMP);
             }
 
+            // a stored timestamp more than a day ahead of this clock cannot 
say the index is up to date
+            if (localTimestamp != null
+                    && localTimestamp.getTime() > System.currentTimeMillis() + 
TimeUnit.DAYS.toMillis(1)) {
+                localTimestamp = null;
+            }
+
             // this will download and store properties in the target, so next 
run
             // target.getProperties() will retrieve it
             Properties remoteProperties = target.setProperties(source);
diff --git 
a/indexer-core/src/test/java/org/apache/maven/index/updater/DefaultIndexUpdaterTest.java
 
b/indexer-core/src/test/java/org/apache/maven/index/updater/DefaultIndexUpdaterTest.java
index 41ff95ee..32564d88 100644
--- 
a/indexer-core/src/test/java/org/apache/maven/index/updater/DefaultIndexUpdaterTest.java
+++ 
b/indexer-core/src/test/java/org/apache/maven/index/updater/DefaultIndexUpdaterTest.java
@@ -371,6 +371,39 @@ class DefaultIndexUpdaterTest extends 
AbstractIndexUpdaterTest {
         assertIndexUpdateSucceeded(updateResult);
     }
 
+    @Test
+    void fullIndexUpdateWhenLocalTimestampIsInTheFuture() throws Exception {
+        String indexUrl = repositoryUrl + ".index";
+        Date contextTimestamp = df.parse("20081125010000.000 -0600");
+
+        ResourceFetcher mockFetcher = mock(ResourceFetcher.class);
+        IndexingContext tempContext = mock(IndexingContext.class);
+
+        Properties localProps = new Properties();
+        localProps.setProperty(IndexingContext.INDEX_TIMESTAMP, 
"20991231000000.000 -0600");
+
+        
when(tempContext.getIndexDirectoryFile()).thenReturn(indexDirectoryWithProperties(localProps,
 testBasedir));
+        when(tempContext.getTimestamp()).thenReturn(contextTimestamp);
+        when(tempContext.getId()).thenReturn(repositoryId);
+        when(tempContext.getIndexUpdateUrl()).thenReturn(indexUrl);
+        when(tempContext.getIndexCreators()).thenReturn(DEFAULT_CREATORS);
+        doNothing().when(tempContext).commit();
+
+        Properties remoteProps = new Properties();
+        remoteProps.setProperty(IndexingContext.INDEX_ID, "central");
+        remoteProps.setProperty(IndexingContext.INDEX_TIMESTAMP, 
"20081126010000.000 -0600");
+        
when(mockFetcher.retrieve(IndexingContext.INDEX_REMOTE_PROPERTIES_FILE))
+                .thenReturn(propertiesStream(remoteProps));
+        when(mockFetcher.retrieve(IndexingContext.INDEX_FILE_PREFIX + ".gz"))
+                
.thenReturn(newInputStream("index-updater/server-root/nexus-maven-repository-index.gz"));
+
+        IndexUpdateResult updateResult = updater.fetchAndUpdateIndex(new 
IndexUpdateRequest(tempContext, mockFetcher));
+
+        verify(mockFetcher).retrieve(IndexingContext.INDEX_FILE_PREFIX + 
".gz");
+        verify(tempContext).replace(any(Directory.class), anySet(), anySet());
+        assertIndexUpdateSucceeded(updateResult);
+    }
+
     @Test
     void fullIndexUpdate() throws Exception {
         String indexUrl = repositoryUrl + ".index";

Reply via email to