@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; }
/** * Get the inactive history directories. * * @return the inactive history */ public List<File> getInactiveHistory() throws PatchingException { if (validHistory == null) { walk(); } final File[] inactiveDirs = installedIdentity.getInstalledImage().getPatchesDir().listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.isDirectory() && !validHistory.contains(pathname.getName()); } }); return inactiveDirs == null ? Collections.<File>emptyList() : Arrays.asList(inactiveDirs); }
/** * Get the inactive history directories. * * @return the inactive history */ public List<File> getInactiveHistory() throws PatchingException { if (validHistory == null) { walk(); } final File[] inactiveDirs = installedIdentity.getInstalledImage().getPatchesDir().listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.isDirectory() && !validHistory.contains(pathname.getName()); } }); return inactiveDirs == null ? Collections.<File>emptyList() : Arrays.asList(inactiveDirs); }
@Override public Patch getMetadata() { if(patch == null) { final File patchDir = i.mgr.getInstalledImage().getPatchHistoryDir(entryPatchId); if(patchDir.exists()) { final File patchXml = new File(patchDir, "patch.xml"); if(patchXml.exists()) { try { patch = ((PatchBuilder)PatchXml.parse(patchXml)).build(); } catch (Exception e) { PatchLogger.ROOT_LOGGER.error(e.getLocalizedMessage(), e); throw new IllegalStateException(patchXml + " is corrupted"); } } } else { throw new IllegalStateException("Failed to locate patch " + entryPatchId + " in the history"); } } return patch; }
@Override public Patch getMetadata() { if(patch == null) { final File patchDir = i.mgr.getInstalledImage().getPatchHistoryDir(entryPatchId); if(patchDir.exists()) { final File patchXml = new File(patchDir, "patch.xml"); if(patchXml.exists()) { try { patch = ((PatchBuilder)PatchXml.parse(patchXml)).build(); } catch (Exception e) { PatchLogger.ROOT_LOGGER.error(e.getLocalizedMessage(), e); throw new IllegalStateException(patchXml + " is corrupted"); } } } else { throw new IllegalStateException("Failed to locate patch " + entryPatchId + " in the history"); } } return patch; }
private static void assertExistsOnDisk(IteratorImpl i, String id) throws NoSuchElementException { final File historyDir = i.mgr.getInstalledImage().getPatchHistoryDir(id); if(!historyDir.exists()) { throw new NoSuchElementException(PatchLogger.ROOT_LOGGER.noPatchHistory(historyDir.getAbsolutePath())); } // TODO parsed xml can be cached final File rollbackXml = new File(historyDir, "rollback.xml"); if(!rollbackXml.exists()) { throw new NoSuchElementException(PatchLogger.ROOT_LOGGER.patchIsMissingFile(rollbackXml.getAbsolutePath())); } try { PatchXml.parse(rollbackXml); } catch (Exception e) { throw new NoSuchElementException(PatchLogger.ROOT_LOGGER.fileIsNotReadable(rollbackXml.getAbsolutePath() + ": " + e.getLocalizedMessage())); } final File patchXml = new File(historyDir, "patch.xml"); if(!patchXml.exists()) { throw new NoSuchElementException(PatchLogger.ROOT_LOGGER.patchIsMissingFile(patchXml.getAbsolutePath())); } final Patch patchMetaData; try { patchMetaData = PatchXml.parse(patchXml).resolvePatch(i.mgr.getIdentity().getName(), i.mgr.getIdentity().getVersion()); } catch (Exception e) { throw new NoSuchElementException(PatchLogger.ROOT_LOGGER.fileIsNotReadable(patchXml.getAbsolutePath() + ": " + e.getLocalizedMessage())); } if(i.excludeAgedOut && isAgedOut(i.mgr, patchMetaData)) { throw new NoSuchElementException("Patch " + patchMetaData.getPatchId() + " was aged out"); } }
private static void assertExistsOnDisk(IteratorImpl i, String id) throws NoSuchElementException { final File historyDir = i.mgr.getInstalledImage().getPatchHistoryDir(id); if(!historyDir.exists()) { throw new NoSuchElementException(PatchLogger.ROOT_LOGGER.noPatchHistory(historyDir.getAbsolutePath())); } // TODO parsed xml can be cached final File rollbackXml = new File(historyDir, "rollback.xml"); if(!rollbackXml.exists()) { throw new NoSuchElementException(PatchLogger.ROOT_LOGGER.patchIsMissingFile(rollbackXml.getAbsolutePath())); } try { PatchXml.parse(rollbackXml); } catch (Exception e) { throw new NoSuchElementException(PatchLogger.ROOT_LOGGER.fileIsNotReadable(rollbackXml.getAbsolutePath() + ": " + e.getLocalizedMessage())); } final File patchXml = new File(historyDir, "patch.xml"); if(!patchXml.exists()) { throw new NoSuchElementException(PatchLogger.ROOT_LOGGER.patchIsMissingFile(patchXml.getAbsolutePath())); } final Patch patchMetaData; try { patchMetaData = PatchXml.parse(patchXml).resolvePatch(i.mgr.getIdentity().getName(), i.mgr.getIdentity().getVersion()); } catch (Exception e) { throw new NoSuchElementException(PatchLogger.ROOT_LOGGER.fileIsNotReadable(patchXml.getAbsolutePath() + ": " + e.getLocalizedMessage())); } if(i.excludeAgedOut && isAgedOut(i.mgr, patchMetaData)) { throw new NoSuchElementException("Patch " + patchMetaData.getPatchId() + " was aged out"); } }
@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 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); }
final File patchHistoryDir = installedIdentity.getInstalledImage().getPatchHistoryDir(entry.getPatchId()); if (patchHistoryDir.exists()) { ops.add(new DeleteOp(patchHistoryDir, HISTORY_FILTER));
final File patchHistoryDir = installedIdentity.getInstalledImage().getPatchHistoryDir(entry.getPatchId()); if (patchHistoryDir.exists()) { ops.add(new DeleteOp(patchHistoryDir, HISTORY_FILTER));
File patchHistoryDir = i.mgr.getInstalledImage().getPatchHistoryDir(releaseID); if(patchHistoryDir.exists()) { final File rollbackXml = new File(patchHistoryDir, "rollback.xml");
File patchHistoryDir = i.mgr.getInstalledImage().getPatchHistoryDir(releaseID); if(patchHistoryDir.exists()) { final File rollbackXml = new File(patchHistoryDir, "rollback.xml");
final File patchHistoryDir = i.mgr.getInstalledImage().getPatchHistoryDir(releaseID); if(patchHistoryDir.exists()) { final File rollbackXml = new File(patchHistoryDir, "rollback.xml");
final File patchHistoryDir = i.mgr.getInstalledImage().getPatchHistoryDir(releaseID); if(patchHistoryDir.exists()) { final File rollbackXml = new File(patchHistoryDir, "rollback.xml");
protected static InstalledIdentity copy(InstalledIdentity original) throws IOException { final InstalledIdentityImpl copy = new InstalledIdentityImpl(original.getIdentity(), original.getAllInstalledPatches(), original.getInstalledImage()); for (final Layer layer : original.getLayers()) { copy.putLayer(layer.getName(), new LayerInfo(layer.getName(), layer.loadTargetInfo(), layer.getDirectoryStructure())); } for (final AddOn addOn : original.getAddOns()) { copy.putAddOn(addOn.getName(), new LayerInfo(addOn.getName(), addOn.loadTargetInfo(), addOn.getDirectoryStructure())); } return copy; }
protected static InstalledIdentity copy(InstalledIdentity original) throws IOException { final InstalledIdentityImpl copy = new InstalledIdentityImpl(original.getIdentity(), original.getAllInstalledPatches(), original.getInstalledImage()); for (final Layer layer : original.getLayers()) { copy.putLayer(layer.getName(), new LayerInfo(layer.getName(), layer.loadTargetInfo(), layer.getDirectoryStructure())); } for (final AddOn addOn : original.getAddOns()) { copy.putAddOn(addOn.getName(), new LayerInfo(addOn.getName(), addOn.loadTargetInfo(), addOn.getDirectoryStructure())); } return copy; }
@Test public void testWrongModuleContent() throws Exception { final PatchingTestBuilder builder = createDefaultBuilder(); // Add some random content ContentModificationUtils.addModule(builder.getRoot(), "base-patch-001", "test.module", randomString()); // Override the hash with a wrong one final ModuleItem item = new ModuleItem("test.module", "main", WRONG_HASH); final ContentModification wrongModification = new ContentModification(item, IoUtils.NO_CONTENT, ModificationType.ADD); final PatchingTestStepBuilder step1 = builder.createStepBuilder(); step1.oneOffPatchIdentity(PRODUCT_VERSION) .setPatchId("oo1") .oneOffPatchElement("base-patch-001", "base", false) .addContentModification(wrongModification) .getParent() .addFileWithRandomContent(null, "test", "content"); // try { apply(step1); Assert.fail("should have failed"); } catch (PatchingException e) { Assert.assertFalse(builder.hasFile("test", "content")); final InstalledIdentity identity = loadInstallationManager().getDefaultIdentity(); final PatchableTarget base = identity.getLayer("base"); Assert.assertFalse(base.getDirectoryStructure().getModulePatchDirectory("base-patch-001").exists()); Assert.assertFalse(identity.getInstalledImage().getPatchHistoryDir("oo1").exists()); } }
@Test public void testWrongMiscContent() throws Exception { final PatchingTestBuilder builder = createDefaultBuilder(); ContentModificationUtils.addMisc(builder.getRoot(), "oo2", "test-content", "wrong-content"); final MiscContentItem item = new MiscContentItem("wrong-content", new String[0], WRONG_HASH); final ContentModification wrongModification = new ContentModification(item, IoUtils.NO_CONTENT, ModificationType.ADD); final PatchingTestStepBuilder step1 = builder.createStepBuilder(); step1.oneOffPatchIdentity(PRODUCT_VERSION) .setPatchId("oo2") .oneOffPatchElement("base-patch-002", "base", false) .addModuleWithRandomContent("other.test", null) .getParent() .addFileWithRandomContent(null, "test", "content") .addContentModification(wrongModification) ; // try { apply(step1); Assert.fail("should have failed"); } catch (PatchingException e) { Assert.assertFalse(builder.hasFile("test", "content")); Assert.assertFalse(builder.hasFile("wrong-content")); final InstalledIdentity identity = loadInstallationManager().getDefaultIdentity(); final PatchableTarget base = identity.getLayer("base"); Assert.assertFalse(base.getDirectoryStructure().getModulePatchDirectory("base-patch-002").exists()); Assert.assertFalse(identity.getInstalledImage().getPatchHistoryDir("oo2").exists()); } }