public byte[] getTargetHash() { return modification.getTargetHash(); }
public byte[] getTargetHash() { return modification.getTargetHash(); }
public ContentModification(ContentItem item, ContentModification existing) { this(item, existing.getTargetHash(), existing.getType()); }
public ContentModification(ContentItem item, ContentModification existing) { this(item, existing.getTargetHash(), existing.getType()); }
protected ContentModification getOriginalModification(byte[] targetHash, byte[] itemHash) { final ContentModification original = super.getOriginalModification(targetHash, itemHash); final ModificationType type; if (Arrays.equals(NO_CONTENT, itemHash) && !backup.exists()) { type = ModificationType.ADD; } else { type = ModificationType.MODIFY; } return new ContentModification(original.getItem(), original.getTargetHash(), type, original.getCondition()); } }
@Override public boolean prepare(PatchingTaskContext context) throws IOException { // we create the backup in any case, since it is possible that the task // will be processed anyhow if the user specified OVERRIDE_ALL policy. // If the task is undone, the patch history will be deleted (including this backup). backup(target, backup, Arrays.asList(item.getPath()), rollback, context); // See if the hash matches the metadata boolean isEmptyDirectory = false; if (target.isDirectory()) { final File[] children = target.listFiles(); if (children == null || children.length == 0) { isEmptyDirectory = true; } } final byte[] expected = description.getModification().getTargetHash(); final byte[] actual = isEmptyDirectory ? NO_CONTENT : HashUtils.hashFile(target); return Arrays.equals(expected, actual); }
protected ContentModification getOriginalModification(byte[] targetHash, byte[] itemHash) { final ContentModification original = super.getOriginalModification(targetHash, itemHash); final ModificationType type; if (Arrays.equals(NO_CONTENT, itemHash) && !backup.exists()) { type = ModificationType.ADD; } else { type = ModificationType.MODIFY; } return new ContentModification(original.getItem(), original.getTargetHash(), type, original.getCondition()); } }
@Override public boolean prepare(PatchingTaskContext context) throws IOException { // we create the backup in any case, since it is possible that the task // will be processed anyhow if the user specified OVERRIDE_ALL policy. // If the task is undone, the patch history will be deleted (including this backup). backup(target, backup, Arrays.asList(item.getPath()), rollback, context); // See if the hash matches the metadata boolean isEmptyDirectory = false; if (target.isDirectory()) { final File[] children = target.listFiles(); if (children == null || children.length == 0) { isEmptyDirectory = true; } } final byte[] expected = description.getModification().getTargetHash(); final byte[] actual = isEmptyDirectory ? NO_CONTENT : HashUtils.hashFile(target); return Arrays.equals(expected, actual); }
@Override public boolean prepare(final PatchingTaskContext context) throws IOException { // Backup backupHash = backup(context); // If the content is already present just resolve any conflict automatically final byte[] contentHash = contentItem.getContentHash(); if(Arrays.equals(backupHash, contentHash)) { return true; } // See if the content matches our expected target final byte[] expected = description.getModification().getTargetHash(); if(Arrays.equals(backupHash, expected)) { // Don't resolve conflicts from the history return ! description.hasConflicts(); } // System.out.println("ModuleUpdateTask.prepare " + description.getModificationType() + " backup " + (backupHash == IoUtils.NO_CONTENT)); // the problem here appears for compact CPs when a module at some point was added then removed and then re-added // re-adding will be MODIFY because the removed module will exist on the FS but will be marked as absent in its module.xml // so applying re-add (MODIFY) to the version where the module didn't exist will fail return false; }
@Override public boolean prepare(final PatchingTaskContext context) throws IOException { // Backup backupHash = backup(context); // If the content is already present just resolve any conflict automatically final byte[] contentHash = contentItem.getContentHash(); if(Arrays.equals(backupHash, contentHash)) { return true; } // See if the content matches our expected target final byte[] expected = description.getModification().getTargetHash(); if(Arrays.equals(backupHash, expected)) { // Don't resolve conflicts from the history return ! description.hasConflicts(); } // System.out.println("ModuleUpdateTask.prepare " + description.getModificationType() + " backup " + (backupHash == IoUtils.NO_CONTENT)); // the problem here appears for compact CPs when a module at some point was added then removed and then re-added // re-adding will be MODIFY because the removed module will exist on the FS but will be marked as absent in its module.xml // so applying re-add (MODIFY) to the version where the module didn't exist will fail return false; }
@Override public boolean prepare(final PatchingTaskContext context) throws IOException { // Backup backupHash = backup(context); // If the content is already present just resolve any conflict automatically final byte[] contentHash = contentItem.getContentHash(); if(Arrays.equals(backupHash, contentHash)) { // Skip execute for misc items only skipExecution = contentItem.getContentType() == ContentType.MISC && backupHash != NO_CONTENT; return true; } // See if the content matches our expected target final byte[] expected = description.getModification().getTargetHash(); if(Arrays.equals(backupHash, expected)) { // Don't resolve conflicts from the history return ! description.hasConflicts(); } return false; }
@Override public boolean prepare(final PatchingTaskContext context) throws IOException { // Backup backupHash = backup(context); // If the content is already present just resolve any conflict automatically final byte[] contentHash = contentItem.getContentHash(); if(Arrays.equals(backupHash, contentHash)) { // Skip execute for misc items only skipExecution = contentItem.getContentType() == ContentType.MISC && backupHash != NO_CONTENT; return true; } // See if the content matches our expected target final byte[] expected = description.getModification().getTargetHash(); if(Arrays.equals(backupHash, expected)) { // Don't resolve conflicts from the history return ! description.hasConflicts(); } return false; }
@Override protected ContentModification getOriginalModification(byte[] targetHash, byte[] itemHash) { final ModuleItem original = getContentItem(); final ModuleItem item = new ModuleItem(original.getName(), original.getSlot(), targetHash); return new ContentModification(item, description.getModification().getTargetHash(), ModificationType.MODIFY, description.getModification().getCondition()); }
@Override protected ContentModification getOriginalModification(byte[] targetHash, byte[] itemHash) { final ModuleItem original = getContentItem(); final ModuleItem item = new ModuleItem(original.getName(), original.getSlot(), targetHash); return new ContentModification(item, description.getModification().getTargetHash(), ModificationType.MODIFY, description.getModification().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)); } } }
assertEquals(0, item.getContentHash().length); if(ContentType.MODULE.equals(item.getContentType())) { Assert.assertArrayEquals(moduleHash("base"), mod.getTargetHash()); } else if(ContentType.MISC.equals(item.getContentType())) { Assert.assertArrayEquals(miscHash("base"), mod.getTargetHash()); } else { Assert.assertArrayEquals(bundleHash("base"), mod.getTargetHash());
@Test public void testPreserveExisting() throws Exception { // content-item 'two' replacing 'one', but kept 'four' final RollbackInfo patch01 = createRollbackInfo("patch01", two, one, four, four); // content-item 'three' replacing 'two' final RollbackInfo patch02 = createRollbackInfo("patch02", three, four); // [patch-two, patch-one] final ContentTaskDefinitions defs = process(patch02, patch01); Assert.assertEquals(1, defs.size()); final PatchingTasks.ContentTaskDefinition def = defs.get(new Location(new MiscContentItem(name, path, one))); Assert.assertNotNull(def); Assert.assertTrue(def.hasConflicts()); // We want to got back to four Assert.assertEquals(four, def.getTarget().getItem().getContentHash()); // The recorded action was preserving four Assert.assertEquals(four, def.getTarget().getTargetHash()); // The current content however is three Assert.assertEquals(three, def.getLatest().getTargetHash()); // And originally replaced four Assert.assertEquals(four, def.getLatest().getItem().getContentHash()); // The resulting operation should replace 'three' with 'four' final ContentModification modification = PatchingTaskDescription.resolveDefinition(def); Assert.assertEquals(four, modification.getItem().getContentHash()); Assert.assertEquals(three, modification.getTargetHash()); }
@Test public void testSimple() throws Exception { // content-item 'two' replacing 'one' final RollbackInfo patch01 = createRollbackInfo("patch01", two, one); // content-item 'three' replacing 'two' final RollbackInfo patch02 = createRollbackInfo("patch02", three, two); // [patch-two, patch-one] final ContentTaskDefinitions defs = process(patch02, patch01); Assert.assertEquals(1, defs.size()); final PatchingTasks.ContentTaskDefinition def = defs.get(new Location(new MiscContentItem(name, path, one))); Assert.assertNotNull(def); Assert.assertFalse(def.hasConflicts()); // We want to restore one (from the backup) Assert.assertEquals(one, def.getTarget().getItem().getContentHash()); // The original target was two Assert.assertEquals(two, def.getTarget().getTargetHash()); // The current content however is three Assert.assertEquals(three, def.getLatest().getTargetHash()); // And originally replaced two Assert.assertEquals(two, def.getLatest().getItem().getContentHash()); // The resulting operation should replace 'three' with 'one' final ContentModification modification = PatchingTaskDescription.resolveDefinition(def); Assert.assertEquals(one, modification.getItem().getContentHash()); Assert.assertEquals(three, modification.getTargetHash()); }
@Test public void testOverrideExisting() throws Exception { // content-item 'two' replacing 'four', originally targeting 'one' final RollbackInfo patch01 = createRollbackInfo("patch01", two, one, four, two); // content-item 'three' replacing 'two' final RollbackInfo patch02 = createRollbackInfo("patch02", three, two); // [patch-two, patch-one] final ContentTaskDefinitions defs = process(patch02, patch01); Assert.assertEquals(1, defs.size()); final PatchingTasks.ContentTaskDefinition def = defs.get(new Location(new MiscContentItem(name, path, one))); Assert.assertNotNull(def); Assert.assertTrue(def.hasConflicts()); // We want to restore four (from the backup) Assert.assertEquals(four, def.getTarget().getItem().getContentHash()); // The original target was two Assert.assertEquals(two, def.getTarget().getTargetHash()); // The current content however is three Assert.assertEquals(three, def.getLatest().getTargetHash()); // And originally replaced two Assert.assertEquals(two, def.getLatest().getItem().getContentHash()); // The resulting operation should replace 'three' with 'four' final ContentModification modification = PatchingTaskDescription.resolveDefinition(def); Assert.assertEquals(four, modification.getItem().getContentHash()); Assert.assertEquals(three, modification.getTargetHash()); }