Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VFS - DeleteFilesJob: Fixes job skipping files while iterating over all files when job is not set to simulation #2011

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/main/java/sirius/biz/storage/layer3/DeleteFilesJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import java.nio.file.PathMatcher;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;

Expand Down Expand Up @@ -161,11 +163,14 @@ private boolean handleDirectory(VirtualFile directory) {
});
}

directory.allChildren().excludeDirectories().subTreeOnly().maxDepth(1).iterate(file -> {
List<VirtualFile> files = new ArrayList<>();
// We must collect the files in a list otherwise the iterator will not process all files if they are deleted
// during the iteration.
directory.allChildren().excludeDirectories().subTreeOnly().maxDepth(1).iterate(files::add);
files.stream().takeWhile(ignored -> process.isActive()).forEach(file -> {
if (!handleFile(file)) {
childSkipped.toggle();
}
return process.isActive();
});

if (!recursive || isRoot) {
Expand Down