/** 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)); } } }
/** * Backup all xml files in a given directory. * * @param source the source directory * @param target the target directory * @throws IOException for any error */ static void backupDirectory(final File source, final File target) throws IOException { if (!target.exists()) { if (!target.mkdirs()) { throw PatchMessages.MESSAGES.cannotCreateDirectory(target.getAbsolutePath()); } } final File[] files = source.listFiles(CONFIG_FILTER); for (final File file : files) { final File t = new File(target, file.getName()); IoUtils.copyFile(file, t); } }
@After public void cleanupForAll() throws Exception { if (controller.isStarted()) { controller.stop(); } // clean up created temporary files and directories if (DO_CLEANUP) { if (IoUtils.recursiveDelete(tempDir)) { tempDir.deleteOnExit(); } } rollbackAllPatches(); }
/** * Write the patch.xml * * @param rollbackPatch the patch * @param file the target file * @throws IOException */ static void writePatch(final Patch rollbackPatch, final File file) throws IOException { final File parent = file.getParentFile(); if (!parent.isDirectory()) { if (!parent.mkdirs() && !parent.exists()) { throw PatchMessages.MESSAGES.cannotCreateDirectory(file.getAbsolutePath()); } } try { final OutputStream os = new FileOutputStream(file); try { PatchXml.marshal(os, rollbackPatch); } finally { IoUtils.safeClose(os); } } catch (XMLStreamException e) { throw new IOException(e); } }