/** Cleanup the history directories for all recorded rolled back patches. */
 protected void cleanupRollbackPatchHistory() {
   final DirectoryStructure structure = getDirectoryStructure();
   for (final String rollback : rollbacks) {
     if (!IoUtils.recursiveDelete(structure.getBundlesPatchDirectory(rollback))) {
       failedToCleanupDir(structure.getBundlesPatchDirectory(rollback));
     }
     if (!IoUtils.recursiveDelete(structure.getModulePatchDirectory(rollback))) {
       failedToCleanupDir(structure.getModulePatchDirectory(rollback));
     }
   }
 }
 /**
  * Add a rollback loader for a give patch.
  *
  * @param patchId the patch id.
  * @param target the patchable target
  * @throws XMLStreamException
  * @throws IOException
  */
 private void recordRollbackLoader(final String patchId, PatchableTarget.TargetInfo target) {
   // setup the content loader paths
   final DirectoryStructure structure = target.getDirectoryStructure();
   final InstalledImage image = structure.getInstalledImage();
   final File historyDir = image.getPatchHistoryDir(patchId);
   final File miscRoot = new File(historyDir, PatchContentLoader.MISC);
   final File modulesRoot = structure.getModulePatchDirectory(patchId);
   final File bundlesRoot = structure.getBundlesPatchDirectory(patchId);
   final PatchContentLoader loader = PatchContentLoader.create(miscRoot, bundlesRoot, modulesRoot);
   //
   recordContentLoader(patchId, loader);
 }
 @Override
 public File getTargetFile(ContentItem item) {
   if (item.getContentType() == ContentType.MISC) {
     return IdentityPatchContext.this.getTargetFile((MiscContentItem) item);
   }
   if (applyPatchId == null || state == State.ROLLBACK_ONLY) {
     throw new IllegalStateException(
         "cannot process rollback tasks for modules/bundles"); // internal wrong usage, no i18n
   }
   final File root;
   final DirectoryStructure structure = delegate.getDirectoryStructure();
   if (item.getContentType() == ContentType.BUNDLE) {
     root = structure.getBundlesPatchDirectory(applyPatchId);
   } else {
     root = structure.getModulePatchDirectory(applyPatchId);
   }
   return PatchContentLoader.getModulePath(root, (ModuleItem) item);
 }