protected MiscContentItem createMiscItem(final String name, final List<String> path, final byte[] newHash, final boolean isDirectory) { return new MiscContentItem(name, path, newHash, isDirectory); }
@Override public boolean preserveExisting(ContentItem item) { final ContentType type = item.getContentType(); if(type == ContentType.MISC) { final MiscContentItem misc = (MiscContentItem) item; final String path = misc.getRelativePath(); return preserve.contains(path); } return false; } };
@Override ContentModification createRollbackEntry(ContentModification original, byte[] targetHash, byte[] itemHash) { final MiscContentItem item = new MiscContentItem(contentItem.getName(), contentItem.getPath(), itemHash, contentItem.isDirectory(), contentItem.isAffectsRuntime()); return createRollbackEntry(original, item, targetHash); }
protected boolean accepts(MiscContentItem one, MiscContentItem two) { return one.getName().equals(two.getName()) && one.getRelativePath().equals(two.getRelativePath()); }
for(final String p : item.getPath()) { path.append(p).append(PATH_DELIMITER); path.append(item.getName()); if (item.isDirectory()) { writer.writeAttribute(Attribute.DIRECTORY.name, "true"); writer.writeAttribute(Attribute.HASH.name, bytesToHexString(existingHash)); if(item.isAffectsRuntime()) { writer.writeAttribute(Attribute.IN_RUNTIME_USE.name, "true"); byte[] hash = item.getContentHash(); if(hash.length > 0) { writer.writeAttribute(Attribute.HASH.name, bytesToHexString(hash)); if (item.isAffectsRuntime()) { writer.writeAttribute(Attribute.IN_RUNTIME_USE.name, "true");
/** * Get the relative path. * * @return the relative path */ public String getRelativePath() { final StringBuilder builder = new StringBuilder(); for(final String p : path) { builder.append(p).append("/"); } builder.append(getName()); return builder.toString(); }
@Override byte[] apply(PatchingTaskContext context, PatchContentLoader loader) throws IOException { final MiscContentItem item = contentItem; if(item.isDirectory()) { if(! target.mkdirs() && ! target.isDirectory()) { throw PatchLogger.ROOT_LOGGER.cannotCreateDirectory(target.getAbsolutePath()); } return NO_CONTENT; } else { if (!target.exists()) { createParentDirectories(target, item.getPath(), item.getPath().length, context); } final InputStream is = loader.openContentStream(item); try { // Replace the file return copy(is, target); } finally { safeClose(is); } } }
@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 byte[] backup(PatchingTaskContext context) throws IOException { if(target.isFile()) { // Backup the original in the history directory final byte[] backupHash = IoUtils.copy(target, backup); return backupHash; } else if (contentItem.isDirectory() && target.isDirectory()) { // Completely ignore the apply step if the directory already exists // This will basically skip the creation of the rollback item setIgnoreApply(); } return NO_CONTENT; }
@Override ContentModification createRollbackEntry(ContentModification original, MiscContentItem item, byte[] targetHash) { final ModificationType type; if (Arrays.equals(NO_CONTENT, item.getContentHash()) && !backup.exists()) { type = ModificationType.REMOVE; } else { type = ModificationType.MODIFY; } return new ContentModification(item, targetHash, type, original.getCondition()); }
for(final String p : item.getPath()) { path.append(p).append(PATH_DELIMITER); path.append(item.getName()); if (item.isDirectory()) { writer.writeAttribute(Attribute.DIRECTORY.name, "true"); writer.writeAttribute(Attribute.HASH.name, bytesToHexString(existingHash)); if(item.isAffectsRuntime()) { writer.writeAttribute(Attribute.IN_RUNTIME_USE.name, "true"); byte[] hash = item.getContentHash(); if(hash.length > 0) { writer.writeAttribute(Attribute.HASH.name, bytesToHexString(hash)); if (item.isAffectsRuntime()) { writer.writeAttribute(Attribute.IN_RUNTIME_USE.name, "true");
/** * Get the relative path. * * @return the relative path */ public String getRelativePath() { final StringBuilder builder = new StringBuilder(); for(final String p : path) { builder.append(p).append("/"); } builder.append(getName()); return builder.toString(); }
@Override byte[] apply(PatchingTaskContext context, PatchContentLoader loader) throws IOException { final MiscContentItem item = contentItem; if(item.isDirectory()) { if(! target.mkdirs() && ! target.isDirectory()) { throw PatchLogger.ROOT_LOGGER.cannotCreateDirectory(target.getAbsolutePath()); } return NO_CONTENT; } else { if (!target.exists()) { createParentDirectories(target, item.getPath(), item.getPath().length, context); } final InputStream is = loader.openContentStream(item); try { // Replace the file return copy(is, target); } finally { safeClose(is); } } }
@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 byte[] backup(PatchingTaskContext context) throws IOException { if(target.isFile()) { // Backup the original in the history directory final byte[] backupHash = IoUtils.copy(target, backup); return backupHash; } else if (contentItem.isDirectory() && target.isDirectory()) { // Completely ignore the apply step if the directory already exists // This will basically skip the creation of the rollback item setIgnoreApply(); } return NO_CONTENT; }
@Override ContentModification createRollbackEntry(ContentModification original, MiscContentItem item, byte[] targetHash) { final ModificationType type; if (Arrays.equals(NO_CONTENT, item.getContentHash()) && !backup.exists()) { type = ModificationType.REMOVE; } else { type = ModificationType.MODIFY; } return new ContentModification(item, targetHash, type, original.getCondition()); }
protected MiscContentItem createMiscItem(final String name, final List<String> path, final byte[] newHash, final boolean isDirectory) { return new MiscContentItem(name, path, newHash, isDirectory); }
elementBuilder.addFile(misc.getName(), Arrays.asList(misc.getPath()), misc.getContentHash(), misc.isDirectory()); } else { // bundle final BundleItem bundle = (BundleItem) cp2Item; } 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(); } else if (cp1Item.getContentType().equals(ContentType.MISC)) { final MiscContentItem misc = (MiscContentItem) cp2Mod.getItem(); elementBuilder.modifyFile(misc.getName(), Arrays.asList(misc.getPath()), cp1Mod.getTargetHash(), misc.getContentHash(), misc.isDirectory()); } else { // bundle final BundleItem bundle = (BundleItem) cp2Mod.getItem();