/** * Add a misc file. * * @param name the file name * @param path the relative path * @param newHash the new hash of the added content * @param isDirectory whether the file is a directory or not * @return the builder */ public T addFile(final String name, final List<String> path, final byte[] newHash, final boolean isDirectory) { return addFile(name, path, newHash, isDirectory, null); }
/** * Modify a misc file. * * @param name the file name * @param path the relative path * @param existingHash the existing hash * @param newHash the new hash of the modified content * @param isDirectory whether the file is a directory or not * @return the builder */ public T modifyFile(final String name, final List<String> path, final byte[] existingHash, final byte[] newHash, final boolean isDirectory) { return modifyFile(name, path, existingHash, newHash, isDirectory, null); }
/** * Remove a misc file. * * @param name the file name * @param path the relative path * @param existingHash the existing hash * @param isDirectory whether the file is a directory or not * @return the builder */ public T removeFile(final String name, final List<String> path, final byte[] existingHash, final boolean isDirectory) { return removeFile(name, path, existingHash, isDirectory, null); }
public T modifyFile(final String name, final List<String> path, final byte[] existingHash, final byte[] newHash, final boolean isDirectory, ModificationCondition condition) { final ContentItem item = createMiscItem(name, path, newHash, isDirectory); addContentModification(createContentModification(item, ModificationType.MODIFY, existingHash, condition)); return returnThis(); }
/** * Add a module. * * @param moduleName the module name * @param slot the module slot * @param newHash the new hash of the added content * @return the builder */ public T addModule(final String moduleName, final String slot, final byte[] newHash) { final ContentItem item = createModuleItem(moduleName, slot, newHash); addContentModification(createContentModification(item, ModificationType.ADD, NO_CONTENT)); return returnThis(); }
/** * Modify a bundle. * * @param moduleName the module name * @param slot the module slot * @param existingHash the existing hash * @param newHash the new hash of the modified content * @return the builder */ public T modifyBundle(final String moduleName, final String slot, final byte[] existingHash, final byte[] newHash) { final ContentItem item = createBundleItem(moduleName, slot, newHash); addContentModification(createContentModification(item, ModificationType.MODIFY, existingHash)); return returnThis(); }
final ContentModification cp2Mod = cp2Mods.remove(cp1Mod.getItem()); if (cp2Mod == null) { elementBuilder.addContentModification(cp1Mod); } else { final ModificationType cp1Type = cp1Mod.getType(); if(cp2Type.equals(ModificationType.REMOVE)) { try { elementBuilder.addModule(module.getName(), module.getSlot(), PatchUtils.getAbsentModuleContentHash(module)); } catch (IOException e) { throw new PatchingException("Failed to calculate hash for the removed module " + module.getName(), e); elementBuilder.addModule(module.getName(), module.getSlot(), module.getContentHash()); elementBuilder.addFile(misc.getName(), Arrays.asList(misc.getPath()), misc.getContentHash(), misc.isDirectory()); } else { // bundle final BundleItem bundle = (BundleItem) cp2Item; elementBuilder.addBundle(bundle.getName(), bundle.getSlot(), bundle.getContentHash()); if (cp1Item.getContentType().equals(ContentType.MODULE)) { final ModuleItem module = (ModuleItem) cp2Mod.getItem(); elementBuilder.removeModule(module.getName(), module.getSlot(), cp1Mod.getTargetHash()); } else if (cp1Item.getContentType().equals(ContentType.MISC)) { final MiscContentItem misc = (MiscContentItem) cp2Mod.getItem(); elementBuilder.removeFile(misc.getName(), Arrays.asList(misc.getPath()), cp1Mod.getTargetHash(), misc.isDirectory()); } else { // bundle final BundleItem bundle = (BundleItem) cp2Mod.getItem();
return; } else if (o != null && n == null) { builder.removeFile(o.getName(), o.getParent().getPathAsList(), o.getMetadataHash(), !o.isLeaf(), getCondition(optionalPaths, o)); } else if (o == null && n != null) { boolean directory = !n.isLeaf(); builder.addFile(n.getName(), n.getParent().getPathAsList(), n.getMetadataHash(), directory, getCondition(optionalPaths, n)); builder.modifyFile(n.getName(), n.getParent().getPathAsList(), o.getMetadataHash(), n.getMetadataHash(), !n.isLeaf(), getCondition(optionalPaths, o)); } else {
protected ContentModification createContentModification(final ContentItem item, final ModificationType type, final byte[] existingHash) { return createContentModification(item, type, existingHash, null); }
final ContentModification cp2Mod = cp2Mods.remove(cp1Mod.getItem()); if (cp2Mod == null) { elementBuilder.addContentModification(cp1Mod); } else { final ModificationType cp1Type = cp1Mod.getType(); if(cp2Type.equals(ModificationType.REMOVE)) { try { elementBuilder.addModule(module.getName(), module.getSlot(), PatchUtils.getAbsentModuleContentHash(module)); } catch (IOException e) { throw new PatchingException("Failed to calculate hash for the removed module " + module.getName(), e); elementBuilder.addModule(module.getName(), module.getSlot(), module.getContentHash()); elementBuilder.addFile(misc.getName(), Arrays.asList(misc.getPath()), misc.getContentHash(), misc.isDirectory()); } else { // bundle final BundleItem bundle = (BundleItem) cp2Item; elementBuilder.addBundle(bundle.getName(), bundle.getSlot(), bundle.getContentHash()); if (cp1Item.getContentType().equals(ContentType.MODULE)) { final ModuleItem module = (ModuleItem) cp2Mod.getItem(); elementBuilder.removeModule(module.getName(), module.getSlot(), cp1Mod.getTargetHash()); } else if (cp1Item.getContentType().equals(ContentType.MISC)) { final MiscContentItem misc = (MiscContentItem) cp2Mod.getItem(); elementBuilder.removeFile(misc.getName(), Arrays.asList(misc.getPath()), cp1Mod.getTargetHash(), misc.isDirectory()); } else { // bundle final BundleItem bundle = (BundleItem) cp2Mod.getItem();
public T removeFile(final String name, final List<String> path, final byte[] existingHash, final boolean isDirectory, ModificationCondition condition) { final ContentItem item = createMiscItem(name, path, NO_CONTENT, isDirectory); addContentModification(createContentModification(item, ModificationType.REMOVE, existingHash, condition)); return returnThis(); }
/** * Remove a module. * * @param moduleName the module name * @param slot the module slot * @param existingHash the existing hash * @return the builder */ public T removeModule(final String moduleName, final String slot, final byte[] existingHash) { final ContentItem item = createModuleItem(moduleName, slot, NO_CONTENT); addContentModification(createContentModification(item, ModificationType.REMOVE, existingHash)); return returnThis(); }
/** * Add a bundle. * * @param moduleName the module name * @param slot the module slot * @param newHash the new hash of the added content * @return the builder */ public T addBundle(final String moduleName, final String slot, final byte[] newHash) { final ContentItem item = createBundleItem(moduleName, slot, newHash); addContentModification(createContentModification(item, ModificationType.ADD, NO_CONTENT)); return returnThis(); }
protected ContentModification createContentModification(final ContentItem item, final ModificationType type, final byte[] existingHash) { return createContentModification(item, type, existingHash, null); }
public T removeFile(final String name, final List<String> path, final byte[] existingHash, final boolean isDirectory, ModificationCondition condition) { final ContentItem item = createMiscItem(name, path, NO_CONTENT, isDirectory); addContentModification(createContentModification(item, ModificationType.REMOVE, existingHash, condition)); return returnThis(); }
/** * Modify a module. * * @param moduleName the module name * @param slot the module slot * @param existingHash the existing hash * @param newHash the new hash of the modified content * @return the builder */ public T modifyModule(final String moduleName, final String slot, final byte[] existingHash, final byte[] newHash) { final ContentItem item = createModuleItem(moduleName, slot, newHash); addContentModification(createContentModification(item, ModificationType.MODIFY, existingHash)); return returnThis(); }
/** * Remove a bundle. * * @param moduleName the module name * @param slot the module slot * @param existingHash the existing hash * @return the builder */ public T removeBundle(final String moduleName, final String slot, final byte[] existingHash) { final ContentItem item = createBundleItem(moduleName, slot, NO_CONTENT); addContentModification(createContentModification(item, ModificationType.REMOVE, existingHash)); return returnThis(); }
/** * Remove a misc file. * * @param name the file name * @param path the relative path * @param existingHash the existing hash * @param isDirectory whether the file is a directory or not * @return the builder */ public T removeFile(final String name, final List<String> path, final byte[] existingHash, final boolean isDirectory) { return removeFile(name, path, existingHash, isDirectory, null); }
/** * Add a misc file. * * @param name the file name * @param path the relative path * @param newHash the new hash of the added content * @param isDirectory whether the file is a directory or not * @return the builder */ public T addFile(final String name, final List<String> path, final byte[] newHash, final boolean isDirectory) { return addFile(name, path, newHash, isDirectory, null); }
/** * Modify a misc file. * * @param name the file name * @param path the relative path * @param existingHash the existing hash * @param newHash the new hash of the modified content * @param isDirectory whether the file is a directory or not * @return the builder */ public T modifyFile(final String name, final List<String> path, final byte[] existingHash, final byte[] newHash, final boolean isDirectory) { return modifyFile(name, path, existingHash, newHash, isDirectory, null); }