private void deleteDirectory(GridUuid parentId, GridUuid id) throws GridException {
assert parentId != null;
assert id != null;
while (true) {
GridGgfsFileInfo info = meta.info(id);
if (info != null) {
assert info.isDirectory();
Map<String, GridGgfsListingEntry> listing = info.listing();
if (listing.isEmpty())
return; // Directory is empty.
Map<String, GridGgfsListingEntry> delListing;
if (listing.size() <= MAX_DELETE_BATCH)
delListing = listing;
else {
delListing = new HashMap<>(MAX_DELETE_BATCH, 1.0f);
int i = 0;
for (Map.Entry<String, GridGgfsListingEntry> entry : listing.entrySet()) {
delListing.put(entry.getKey(), entry.getValue());
if (++i == MAX_DELETE_BATCH)
break;
}
}
GridCompoundFuture<Object, ?> fut = new GridCompoundFuture<>(ggfsCtx.kernalContext());
// Delegate to child folders.
for (GridGgfsListingEntry entry : delListing.values()) {
if (!cancelled) {
if (entry.isDirectory())
deleteDirectory(id, entry.fileId());
else {
GridGgfsFileInfo fileInfo = meta.info(entry.fileId());
if (fileInfo != null) {
assert fileInfo.isFile();
fut.add(data.delete(fileInfo));
}
}
}