public ModificationType getModificationType() { return modification.getType(); }
public ModificationType getModificationType() { return modification.getType(); }
public ContentModification(ContentItem item, ContentModification existing) { this(item, existing.getTargetHash(), existing.getType()); }
public ContentModification(ContentItem item, ContentModification existing) { this(item, existing.getTargetHash(), existing.getType()); }
@Override ContentModification createRollbackEntry(ContentModification original, byte[] targetHash, byte[] itemHash) { // Although modules are ignored for rollback, we still keep track of our changes final ModuleItem item = createContentItem(contentItem, itemHash); final ModificationType type; // Check if the module did not exist before. Invalidated patches might include the module already // and we need to track that they can be rolled back to the last state if (original.getType() != ModificationType.MODIFY && itemHash.length == 0) { type = ModificationType.REMOVE; } else { type = ModificationType.MODIFY; } return new ContentModification(item, targetHash, type, original.getCondition()); }
@Override ContentModification createRollbackEntry(ContentModification original, byte[] targetHash, byte[] itemHash) { // Although modules are ignored for rollback, we still keep track of our changes final ModuleItem item = createContentItem(contentItem, itemHash); final ModificationType type; // Check if the module did not exist before. Invalidated patches might include the module already // and we need to track that they can be rolled back to the last state if (original.getType() != ModificationType.MODIFY && itemHash.length == 0) { type = ModificationType.REMOVE; } else { type = ModificationType.MODIFY; } return new ContentModification(item, targetHash, type, original.getCondition()); }
/** * Recursively copy modification items. * * @param modifications the modifications * @throws IOException */ protected void copyItems(final Collection<ContentModification> modifications) throws IOException { for (final ContentModification modification : modifications) { if (modification.getType() == ModificationType.REMOVE) { // Skip removals continue; } final ContentItem item = modification.getItem(); final File source = getSourceFile(item); final File target = getTargetFile(item); if (!source.exists()) { throw processingError("source item does not exist %s", source.getAbsolutePath()); } IoUtils.copyFile(source, target); } }
@Override ContentModification createRollbackEntry(ContentModification original, byte[] targetHash, byte[] itemHash) { final BundleItem item = new BundleItem(contentItem.getName(), contentItem.getSlot(), itemHash); switch (original.getType()) { case ADD: return new ContentModification(item, targetHash, ModificationType.REMOVE, original.getCondition()); case REMOVE: return new ContentModification(item, targetHash, ModificationType.ADD, original.getCondition()); default: return new ContentModification(item, targetHash, ModificationType.MODIFY, original.getCondition()); } }
@Override ContentModification createRollbackEntry(ContentModification original, byte[] targetHash, byte[] itemHash) { final BundleItem item = new BundleItem(contentItem.getName(), contentItem.getSlot(), itemHash); switch (original.getType()) { case ADD: return new ContentModification(item, targetHash, ModificationType.REMOVE, original.getCondition()); case REMOVE: return new ContentModification(item, targetHash, ModificationType.ADD, original.getCondition()); default: return new ContentModification(item, targetHash, ModificationType.MODIFY, original.getCondition()); } }
final ModificationType type = modification.getType();
static ContentModification resolveDefinition(final PatchingTasks.ContentTaskDefinition definition) { // Only available in a single patch, yay! if(definition.getLatest() == definition.getTarget()) { return definition.getTarget().getModification(); } // Create a new modification replacing the latest final ContentItem backupItem = definition.getTarget().getItem(); final ContentModification modification = definition.getTarget().getModification(); final byte[] target = definition.getLatest().getTargetHash(); return new ContentModification(backupItem, target, modification.getType(), modification.getCondition()); }
static ContentModification resolveDefinition(final PatchingTasks.ContentTaskDefinition definition) { // Only available in a single patch, yay! if(definition.getLatest() == definition.getTarget()) { return definition.getTarget().getModification(); } // Create a new modification replacing the latest final ContentItem backupItem = definition.getTarget().getItem(); final ContentModification modification = definition.getTarget().getModification(); final byte[] target = definition.getLatest().getTargetHash(); return new ContentModification(backupItem, target, modification.getType(), modification.getCondition()); }
protected static void writeSlottedItem(final XMLExtendedStreamWriter writer, Element element, ContentModification modification) throws XMLStreamException { writer.writeEmptyElement(element.name); final ModuleItem item = (ModuleItem) modification.getItem(); final ModificationType type = modification.getType(); writer.writeAttribute(Attribute.NAME.name, item.getName()); if (!MAIN_SLOT.equals(item.getSlot())) { writer.writeAttribute(Attribute.SLOT.name, item.getSlot()); } byte[] hash = item.getContentHash(); if (hash.length > 0 && type != ModificationType.REMOVE) { writer.writeAttribute(Attribute.HASH.name, bytesToHexString(hash)); } if(type == ModificationType.REMOVE) { final byte[] existingHash = modification.getTargetHash(); if (existingHash.length > 0) { writer.writeAttribute(Attribute.HASH.name, bytesToHexString(existingHash)); } } else if(type == ModificationType.MODIFY) { final byte[] existingHash = modification.getTargetHash(); if (existingHash.length > 0) { writer.writeAttribute(Attribute.NEW_HASH.name, bytesToHexString(existingHash)); } } }
protected static void writeSlottedItem(final XMLExtendedStreamWriter writer, Element element, ContentModification modification) throws XMLStreamException { writer.writeEmptyElement(element.name); final ModuleItem item = (ModuleItem) modification.getItem(); final ModificationType type = modification.getType(); writer.writeAttribute(Attribute.NAME.name, item.getName()); if (!MAIN_SLOT.equals(item.getSlot())) { writer.writeAttribute(Attribute.SLOT.name, item.getSlot()); } byte[] hash = item.getContentHash(); if (hash.length > 0 && type != ModificationType.REMOVE) { writer.writeAttribute(Attribute.HASH.name, bytesToHexString(hash)); } if(type == ModificationType.REMOVE) { final byte[] existingHash = modification.getTargetHash(); if (existingHash.length > 0) { writer.writeAttribute(Attribute.HASH.name, bytesToHexString(existingHash)); } } else if(type == ModificationType.MODIFY) { final byte[] existingHash = modification.getTargetHash(); if (existingHash.length > 0) { writer.writeAttribute(Attribute.NEW_HASH.name, bytesToHexString(existingHash)); } } }
assertMisc(home, modification.getType(), (MiscContentItem) item); break; default:
@Test public void testAddRemove() throws Exception { final Patch cp1 = generateCP("base", "cp1", ModificationType.ADD); final Patch cp2 = generateCP("cp1", "cp2", ModificationType.REMOVE); final Patch merged = PatchMerger.merge(cp1, cp2); assertEquals("cp2", merged.getPatchId()); assertEquals("cp2" + " description", merged.getDescription()); final IdentityUpgrade identity = merged.getIdentity().forType(PatchType.CUMULATIVE, Identity.IdentityUpgrade.class); assertEquals("base", identity.getVersion()); assertEquals("cp2", identity.getResultingVersion()); assertEquals(PatchType.CUMULATIVE, identity.getPatchType()); final List<PatchElement> elements = merged.getElements(); assertEquals(1, elements.size()); final PatchElement e = elements.get(0); assertEquals("base-" + "cp2", e.getId()); final PatchElementProvider provider = e.getProvider(); assertEquals("base", provider.getName()); assertEquals(PatchType.CUMULATIVE, provider.getPatchType()); assertEquals(LayerType.Layer, provider.getLayerType()); //assertEquals(0, e.getModifications().size()); // for modules remove is effectively a modify which changes the module xml to indicate an absent module // so, it will remain an add of an absent module assertEquals(1, e.getModifications().size()); final ContentModification mod = e.getModifications().iterator().next(); assertEquals(ModificationType.ADD, mod.getType()); Assert.assertArrayEquals(PatchUtils.getAbsentModuleContentHash((ModuleItem) mod.getItem()), mod.getItem().getContentHash()); }
assertEquals(ModificationType.ADD, mod.getType()); final ContentItem item = mod.getItem(); assertEquals(0, mod.getTargetHash().length);
assertEquals(ModificationType.REMOVE, mod.getType()); final ContentItem item = mod.getItem(); assertEquals(0, item.getContentHash().length);
assertEquals(ModificationType.MODIFY, mod.getType()); final ContentItem item = mod.getItem(); if(ContentType.MODULE.equals(item.getContentType())) {
assertEquals(ModificationType.MODIFY, mod.getType()); final ContentItem item = mod.getItem(); if(ContentType.MODULE.equals(item.getContentType())) {