From 8d0460572a386703e5fdda137e06eedd5798b4e3 Mon Sep 17 00:00:00 2001 From: Laurettta Date: Mon, 9 Nov 2026 09:33:33 +0000 Subject: [PATCH] Fix restore progress stopping at 94.1% by not counting descriptors twice Closes https://github.com/eXist-db/exist/issues/3730 --- .../main/java/org/exist/backup/Restore.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/exist-core/src/main/java/org/exist/backup/Restore.java b/exist-core/src/main/java/org/exist/backup/Restore.java index b66debebf9..9dda5bfb58 100644 --- a/exist-core/src/main/java/org/exist/backup/Restore.java +++ b/exist-core/src/main/java/org/exist/backup/Restore.java @@ -97,6 +97,7 @@ public void restore(final DBBroker broker, @Nullable final Txn transaction, fina // count all files long totalNrOfFiles = 0; for (BackupDescriptor backupDescriptor : descriptors) { + if (!isInsideAnotherDescriptor(backupDescriptor, descriptors)) totalNrOfFiles += backupDescriptor.getNumberOfFiles(); } @@ -131,6 +132,23 @@ public void restore(final DBBroker broker, @Nullable final Txn transaction, fina } } } + + private boolean isInsideAnotherDescriptor(final BackupDescriptor descriptor, final Deque descriptors) { + final String pathToCheck = descriptor.getSymbolicPath(); + for (final BackupDescriptor otherDescriptor : descriptors) { + if (otherDescriptor == (descriptor)) { + continue; + } + final String otherPathDescriptorPath = otherDescriptor.getSymbolicPath(); + if(otherPathDescriptorPath.endsWith(BackupDescriptor.COLLECTION_DESCRIPTOR)) { + final String outerFolder = otherPathDescriptorPath.substring(0, otherPathDescriptorPath.length() - BackupDescriptor.COLLECTION_DESCRIPTOR.length()); + if (pathToCheck.startsWith(outerFolder)) { + return true; + } + } + } + return false; + } private Deque getBackupDescriptors(Path contents) throws IOException { final Deque descriptors = new ArrayDeque<>();