Commit 42a0dd28 authored by Karsten Loesing's avatar Karsten Loesing
Browse files

Correctly index files that are moved away and back.

The indexer did not handle a (mostly theoretic) edge case of a file
being moved away and then moved back shortly after. In such a case the
file should not be marked for deletion anymore and it should be
included in the index again. That's what this commit does.

The other minor changes to unit tests are just cosmetic.

Fixes #34030.
parent cd15f344
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -426,6 +426,12 @@ public class CreateIndexJson extends CollecTorMain {
          /* We do have index results, but we don't have a link yet, so we're
           * going to create a link. */
          linksToCreate.put(linkPath, filePath);
          if (null != fileNode.markedForDeletion) {
            /* We had already marked the link for deletion, but given that the
             * original file has returned, we're going to list this file again
             * and not delete the link in the future. */
            fileNode.markedForDeletion = null;
          }
        } else {
          String linkLastModified = dateTimeFormatter
              .format(Files.getLastModifiedTime(linkPath).toInstant());
+20 −3
Original line number Diff line number Diff line
@@ -404,8 +404,7 @@ public class CreateIndexJsonTest {
    createFile(recentExitListFilePath, Instant.parse("2016-09-20T13:02:00Z"));
    writeIndexJson(recentExitListIndexJsonString);
    startProcessing(firstExecution);
    startProcessing(secondExecution);
    assertEquals(recentExitListIndexJsonString, readIndexJson());
    assertTrue(this.indexerTasks.isEmpty());
  }

  /**
@@ -422,7 +421,6 @@ public class CreateIndexJsonTest {
    deleteFile(recentExitListFilePath);
    startProcessing(secondExecution);
    assertEquals(emptyIndexJsonString, readIndexJson());
    fileExists(recentExitListLinkPath);
    assertTrue(fileExists(recentExitListLinkPath));
    startProcessing(thirdExecution);
    assertFalse(fileExists(recentExitListLinkPath));
@@ -518,5 +516,24 @@ public class CreateIndexJsonTest {
    startProcessing(thirdExecution);
    assertTrue(this.indexerTasks.isEmpty());
  }

  /**
   * Test whether a file that was previously contained in the index and deleted
   * or moved away and that is later recreated or moved back to its original
   * location is included in the index again and still has a corresponding link
   * three hours later.
   */
  @Test
  public void testMoveBackFile() {
    writeIndexJson(recentExitListIndexJsonString);
    startProcessing(firstExecution);
    createFile(recentExitListFilePath, Instant.parse("2016-09-20T13:02:00Z"));
    startProcessing(secondExecution);
    assertTrue(this.indexerTasks.isEmpty());
    assertTrue(Files.exists(recentExitListLinkPath));
    assertEquals(recentExitListIndexJsonString, readIndexJson());
    startProcessing(thirdExecution);
    assertTrue(Files.exists(recentExitListLinkPath));
  }
}