ReplicationTasksStorage: Handle DirectoryIteratorExceptions (part 2)

These exceptions wrap IOExceptions for methods whose contract doesn't
allow them to throw an IOException. In situations where storage is NFS
based, it's common to have Stale NFS File Handle errors when iterating a
directory that can be moved and undesirable to log each time that
occurs.

Change-Id: I1f3757ad5d2ff55220475b6a81b6f8446d05f7aa
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorage.java b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorage.java
index c764161..b805c72 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorage.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorage.java
@@ -168,11 +168,16 @@
     try (DirectoryStream<Path> dirs = Files.newDirectoryStream(createDir(runningUpdates))) {
       for (Path dir : dirs) {
         UriLock lock = null;
-        for (ReplicateRefUpdate u : list(dir)) {
-          if (lock == null) {
-            lock = new UriLock(u);
+        try {
+          for (ReplicateRefUpdate u : list(dir)) {
+            if (lock == null) {
+              lock = new UriLock(u);
+            }
+            new Task(u).reset();
           }
-          new Task(u).reset();
+        } catch (DirectoryIteratorException d) {
+          // iterating over the sub-directories is expected to have dirs disappear
+          Nfs.throwIfNotStaleFileHandle(d.getCause());
         }
         if (lock != null) {
           lock.release();