if (parentId == null) {
// Handle special case when we deleting root directory.
assert ROOT_ID.equals(id);
GridGgfsFileInfo rootInfo = id2InfoPrj.get(ROOT_ID);
if (rootInfo == null)
return null; // Root was never created.
// Ensure trash directory existence.
if (id2InfoPrj.get(TRASH_ID) == null)
id2InfoPrj.put(TRASH_ID, new GridGgfsFileInfo(TRASH_ID));
Map<String, GridGgfsListingEntry> rootListing = rootInfo.listing();
if (!rootListing.isEmpty()) {
GridUuid[] lockIds = new GridUuid[rootInfo.listing().size()];
int i = 0;
for (GridGgfsListingEntry entry : rootInfo.listing().values())
lockIds[i++] = entry.fileId();
// Lock children IDs in correct order.
lockIds(lockIds);
// Construct new info and move locked entries from root to it.
Map<String, GridGgfsListingEntry> transferListing = new HashMap<>();
transferListing.putAll(rootListing);
GridGgfsFileInfo newInfo = new GridGgfsFileInfo(transferListing);
id2InfoPrj.put(newInfo.id(), newInfo);
// Add new info to trash listing.
id2InfoPrj.transform(TRASH_ID, new UpdateListing(newInfo.id().toString(),
new GridGgfsListingEntry(newInfo), false));
// Remove listing entries from root.
for (Map.Entry<String, GridGgfsListingEntry> entry : transferListing.entrySet())
id2InfoPrj.transform(ROOT_ID, new UpdateListing(entry.getKey(), entry.getValue(), true));
resId = newInfo.id();
}
else
resId = null;
}
else {
// Ensure trash directory existence.
if (id2InfoPrj.get(TRASH_ID) == null)
id2InfoPrj.put(TRASH_ID, new GridGgfsFileInfo(TRASH_ID));
moveNonTx(id, name, parentId, id.toString(), TRASH_ID);
resId = id;
}