[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [collector/master] Correctly index files that are moved away and back.
commit 42a0dd280924cdf1ad5c2be3c6c18536a197c88f
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Sat Nov 28 11:14:21 2020 +0100
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.
---
.../metrics/collector/indexer/CreateIndexJson.java | 6 ++++++
.../collector/indexer/CreateIndexJsonTest.java | 23 +++++++++++++++++++---
2 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/torproject/metrics/collector/indexer/CreateIndexJson.java b/src/main/java/org/torproject/metrics/collector/indexer/CreateIndexJson.java
index 6613e9f..3d86947 100644
--- a/src/main/java/org/torproject/metrics/collector/indexer/CreateIndexJson.java
+++ b/src/main/java/org/torproject/metrics/collector/indexer/CreateIndexJson.java
@@ -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());
diff --git a/src/test/java/org/torproject/metrics/collector/indexer/CreateIndexJsonTest.java b/src/test/java/org/torproject/metrics/collector/indexer/CreateIndexJsonTest.java
index 9c01293..a176d27 100644
--- a/src/test/java/org/torproject/metrics/collector/indexer/CreateIndexJsonTest.java
+++ b/src/test/java/org/torproject/metrics/collector/indexer/CreateIndexJsonTest.java
@@ -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));
+ }
}
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits