static RollbackPatch loadRollbackInformation(final String patchId, final InstalledImage installedImage) throws PatchingException, IOException, XMLStreamException { final File historyDir = installedImage.getPatchHistoryDir(patchId); final File patchXml = new File(historyDir, Constants.ROLLBACK_XML); return (RollbackPatch) PatchXml.parse(patchXml).resolvePatch(null, null); }
static RollbackPatch loadRollbackInformation(final String patchId, final InstalledImage installedImage) throws PatchingException, IOException, XMLStreamException { final File historyDir = installedImage.getPatchHistoryDir(patchId); final File patchXml = new File(historyDir, Constants.ROLLBACK_XML); return (RollbackPatch) PatchXml.parse(patchXml).resolvePatch(null, null); }
static Patch loadPatchInformation(final String patchId, final InstalledImage installedImage) throws PatchingException, IOException, XMLStreamException { final File patchDir = installedImage.getPatchHistoryDir(patchId); final File patchXml = new File(patchDir, PatchXml.PATCH_XML); return PatchXml.parse(patchXml).resolvePatch(null, null); }
static Patch loadPatchInformation(final String patchId, final InstalledImage installedImage) throws PatchingException, IOException, XMLStreamException { final File patchDir = installedImage.getPatchHistoryDir(patchId); final File patchXml = new File(patchDir, PatchXml.PATCH_XML); return PatchXml.parse(patchXml).resolvePatch(null, null); }
@Override public String getAppliedAt() { if(appliedAt == null) { final File patchHistoryDir = i.mgr.getInstalledImage().getPatchHistoryDir(entryPatchId); if(patchHistoryDir.exists()) { try { appliedAt = getAppliedAt(patchHistoryDir); } catch (PatchingException e) { } } } return appliedAt; }
@Override public String getAppliedAt() { if(appliedAt == null) { final File patchHistoryDir = i.mgr.getInstalledImage().getPatchHistoryDir(entryPatchId); if(patchHistoryDir.exists()) { try { appliedAt = getAppliedAt(patchHistoryDir); } catch (PatchingException e) { } } } return appliedAt; }
@Override public void finishPatch(final Patch processedPatch, final RollbackPatch rollbackPatch, final IdentityPatchContext context) throws Exception { final File historyDir = structure.getInstalledImage().getPatchHistoryDir(patchId); if (!historyDir.exists()) { historyDir.mkdirs(); } // Backup the current active patch Info final File timestamp = new File(historyDir, Constants.TIMESTAMP); PatchUtils.writeRef(timestamp, generateTimestamp()); // Persist the processed patch, which contains the records of changes final File backupPatchXml = new File(historyDir, PatchXml.PATCH_XML); IdentityPatchContext.writePatch(processedPatch, backupPatchXml); // Persist the rollback.xml in the history directory final File rollbackPatchXml = new File(historyDir, Constants.ROLLBACK_XML); IdentityPatchContext.writePatch(rollbackPatch, rollbackPatchXml); // Backup the configuration context.backupConfiguration(); }
@Override public void finishPatch(final Patch processedPatch, final RollbackPatch rollbackPatch, final IdentityPatchContext context) throws Exception { final File historyDir = structure.getInstalledImage().getPatchHistoryDir(patchId); if (!historyDir.exists()) { historyDir.mkdirs(); } // Backup the current active patch Info final File timestamp = new File(historyDir, Constants.TIMESTAMP); PatchUtils.writeRef(timestamp, generateTimestamp()); // Persist the processed patch, which contains the records of changes final File backupPatchXml = new File(historyDir, PatchXml.PATCH_XML); IdentityPatchContext.writePatch(processedPatch, backupPatchXml); // Persist the rollback.xml in the history directory final File rollbackPatchXml = new File(historyDir, Constants.ROLLBACK_XML); IdentityPatchContext.writePatch(rollbackPatch, rollbackPatchXml); // Backup the configuration context.backupConfiguration(); }
@Override public boolean process(PatchingArtifacts.PatchID parent, PatchingArtifactProcessor processor) { final InstalledIdentity identity = processor.getValidationContext().getInstalledIdentity(); final File history = identity.getInstalledImage().getPatchHistoryDir(parent.getPatchID()); final PatchingFileArtifact.DirectoryArtifactState state = new PatchingFileArtifact.DirectoryArtifactState(history, this); return processor.process(this, state); }
protected void removeRollbackXml(String patchId) throws IOException { final File oneOff1History = updateInstallationManager().getInstalledImage().getPatchHistoryDir(patchId); assertTrue(oneOff1History.exists()); final File oneOff1RollbackXml = new File(oneOff1History, "rollback.xml"); assertTrue(oneOff1RollbackXml.exists()); assertTrue(oneOff1RollbackXml.delete()); assertFalse(oneOff1RollbackXml.exists()); }
@Override public boolean process(PatchingArtifacts.PatchID parent, PatchingArtifactProcessor processor) { final InstalledIdentity identity = processor.getValidationContext().getInstalledIdentity(); final File history = identity.getInstalledImage().getPatchHistoryDir(parent.getPatchID()); final PatchingFileArtifact.DirectoryArtifactState state = new PatchingFileArtifact.DirectoryArtifactState(history, this); return processor.process(this, state); }
@Override public void completed(IdentityPatchContext context) { final InstalledImage installedImage = directoryStructure.getInstalledImage(); final File history = installedImage.getPatchHistoryDir(patch.getPatchId()); if (!recursiveDelete(history)) { context.failedToCleanupDir(history); } // Cleanup all the recorded rollbacks cleanupEntry(context.getLayers()); cleanupEntry(context.getAddOns()); cleanupEntry(Collections.singleton(context.getIdentityEntry())); }
@Override public void completed(IdentityPatchContext context) { final InstalledImage installedImage = directoryStructure.getInstalledImage(); final File history = installedImage.getPatchHistoryDir(patch.getPatchId()); if (!recursiveDelete(history)) { context.failedToCleanupDir(history); } // Cleanup all the recorded rollbacks cleanupEntry(context.getLayers()); cleanupEntry(context.getAddOns()); cleanupEntry(Collections.singleton(context.getIdentityEntry())); }
static void assertPatchHasNotBeenApplied(ContentConflictsException result, Patch patch, ContentItem problematicItem, DirectoryStructure structure) { assertFalse("patch should have failed", result.getConflicts().isEmpty()); assertTrue(problematicItem + " is not reported in the problems " + result.getConflicts(), result.getConflicts().contains(problematicItem)); assertDirDoesNotExist(structure.getInstalledImage().getPatchHistoryDir(patch.getPatchId())); }
@Test public void testRemovedModifiedFileWithOVERRIDE_ALL() throws Exception { PatchingResult result = runner.applyPatch(zippedPatch, ContentVerificationPolicy.OVERRIDE_ALL); assertPatchHasBeenApplied(result, patch); /// file has been removed from the AS7 installation // and it's the new one assertFileDoesNotExist(removedFile); // the existing file has been backed up File backupFile = assertFileExists(env.getInstalledImage().getPatchHistoryDir(patch.getPatchId()), "misc", "bin", removedFile.getName()); assertArrayEquals(expectedModifiedHash, hashFile(backupFile)); }
@Test public void testUpdateModifiedFileWithOVERRIDE_ALL() throws Exception { PatchingResult result = runner.applyPatch(zippedPatch, ContentVerificationPolicy.OVERRIDE_ALL); assertPatchHasBeenApplied(result, patch); /// file has been updated in the AS7 installation // and it's the new one assertFileExists(modifiedFile); assertArrayEquals(updatedHash, hashFile(modifiedFile)); // the existing file has been backed up File backupFile = assertFileExists(env.getInstalledImage().getPatchHistoryDir(patch.getPatchId()), "misc", "bin", modifiedFile.getName()); assertArrayEquals(expectedModifiedHash, hashFile(backupFile)); }
static void assertNoResourcesForPatch(DirectoryStructure structure, Patch patch) { assertDirDoesNotExist(structure.getModulePatchDirectory(patch.getPatchId())); assertDirDoesNotExist(structure.getBundlesPatchDirectory(patch.getPatchId())); assertDirDoesNotExist(structure.getInstalledImage().getPatchHistoryDir(patch.getPatchId())); }
@Override public void operationCancelled(IdentityPatchContext context) { // Cleanup history, bundles and module patch directories final InstalledImage image = structure.getInstalledImage(); IoUtils.recursiveDelete(image.getPatchHistoryDir(patchId)); IoUtils.recursiveDelete(structure.getBundlesPatchDirectory(patchId)); IoUtils.recursiveDelete(structure.getModulePatchDirectory(patchId)); for (final PatchElement element : original.getElements()) { boolean addOn = element.getProvider().isAddOn(); final IdentityPatchContext.PatchEntry entry = context.getEntry(element.getProvider().getName(), addOn); final DirectoryStructure structure = entry.getDirectoryStructure(); IoUtils.recursiveDelete(structure.getBundlesPatchDirectory(element.getId())); IoUtils.recursiveDelete(structure.getModulePatchDirectory(element.getId())); } }
@Override public void operationCancelled(IdentityPatchContext context) { // Cleanup history, bundles and module patch directories final InstalledImage image = structure.getInstalledImage(); IoUtils.recursiveDelete(image.getPatchHistoryDir(patchId)); IoUtils.recursiveDelete(structure.getBundlesPatchDirectory(patchId)); IoUtils.recursiveDelete(structure.getModulePatchDirectory(patchId)); for (final PatchElement element : original.getElements()) { boolean addOn = element.getProvider().isAddOn(); final IdentityPatchContext.PatchEntry entry = context.getEntry(element.getProvider().getName(), addOn); final DirectoryStructure structure = entry.getDirectoryStructure(); IoUtils.recursiveDelete(structure.getBundlesPatchDirectory(element.getId())); IoUtils.recursiveDelete(structure.getModulePatchDirectory(element.getId())); } }
static void assertNotApplied(final Patch patch, InstallationManager manager) throws IOException { InstalledIdentity installedIdentity = null; try { installedIdentity = manager.getInstalledIdentity(patch.getIdentity().getName(), patch.getIdentity().getVersion()); } catch (PatchingException e) { Assert.fail(e.getLocalizedMessage()); } final PatchableTarget.TargetInfo identity = installedIdentity.getIdentity().loadTargetInfo(); assertNotApplied(patch.getIdentity().getPatchType(), patch.getPatchId(), identity); assertDoesNotExists(identity.getDirectoryStructure().getInstalledImage().getPatchHistoryDir(patch.getPatchId())); for (final PatchElement element : patch.getElements()) { final PatchElementProvider provider = element.getProvider(); final PatchableTarget target = provider.isAddOn() ? installedIdentity.getAddOn(provider.getName()) : installedIdentity.getLayer(provider.getName()); Assert.assertNotNull(target); assertNotApplied(provider.getPatchType(), element.getId(), target.loadTargetInfo()); } }