public static byte[] copy(File source, File target) throws IOException { try (final FileInputStream is = new FileInputStream(source)){ return copy(is, target); } }
public static byte[] copy(File source, File target) throws IOException { try (final FileInputStream is = new FileInputStream(source)){ return copy(is, target); } }
@Override byte[] apply(PatchingTaskContext context, PatchContentLoader loader) throws IOException { final File targetDir = context.getTargetFile(contentItem); if(!targetDir.exists() && ! targetDir.mkdirs()) { throw PatchLogger.ROOT_LOGGER.cannotCreateDirectory(targetDir.getAbsolutePath()); } final File moduleXml = new File(targetDir, MODULE_XML); try (final ByteArrayInputStream is = new ByteArrayInputStream(PatchUtils.getAbsentModuleContent(contentItem))){ return copy(is, moduleXml); } }
@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 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 byte[] apply(PatchingTaskContext context, PatchContentLoader loader) throws IOException { final File targetDir = context.getTargetFile(contentItem); if(!targetDir.exists() && ! targetDir.mkdirs()) { throw PatchLogger.ROOT_LOGGER.cannotCreateDirectory(targetDir.getAbsolutePath()); } final File moduleXml = new File(targetDir, MODULE_XML); try (final ByteArrayInputStream is = new ByteArrayInputStream(PatchUtils.getAbsentModuleContent(contentItem))){ return copy(is, moduleXml); } }
private static File expandContent(File patchFile, final File workDir, final String expandDirName) throws PatchingException { final File patchDir; try { if (!patchFile.isDirectory()) { patchDir = new File(workDir, expandDirName); // Save the content final File cachedContent = new File(patchDir, "content"); IoUtils.copy(patchFile, cachedContent); // Unpack to the work dir ZipUtils.unzip(cachedContent, patchDir); } else { patchDir = patchFile; } } catch (IOException e) { throw new PatchingException("Failed to unzip " + patchFile.getAbsolutePath()); } return patchDir; }
private static File expandContent(File patchFile, final File workDir, final String expandDirName) throws PatchingException { final File patchDir; try { if (!patchFile.isDirectory()) { patchDir = new File(workDir, expandDirName); // Save the content final File cachedContent = new File(patchDir, "content"); IoUtils.copy(patchFile, cachedContent); // Unpack to the work dir ZipUtils.unzip(cachedContent, patchDir); } else { patchDir = patchFile; } } catch (IOException e) { throw new PatchingException("Failed to unzip " + patchFile.getAbsolutePath()); } return patchDir; }
void backup(final File root, final File backupLocation, final List<String> path, final List<ContentModification> rollback, final PatchingTaskContext context) throws IOException { if(!root.exists()) { // Perhaps an error condition? } else if(root.isDirectory()) { final File[] files = root.listFiles(); final String rootName = root.getName(); if(files == null || files.length == 0) { // Create empty directory rollback.add(createRollbackItem(rootName, path, NO_CONTENT, true)); } else { final List<String> newPath = new ArrayList<String>(path); newPath.add(rootName); for (File file : files) { final String name = file.getName(); final File newBackupLocation = new File(backupLocation, name); backup(file, newBackupLocation, newPath, rollback, context); } } } else { // Copy and record the backup action final byte[] hash = copy(root, backupLocation); rollback.add(createRollbackItem(root.getName(), path, hash, false)); } }
void backup(final File root, final File backupLocation, final List<String> path, final List<ContentModification> rollback, final PatchingTaskContext context) throws IOException { if(!root.exists()) { // Perhaps an error condition? } else if(root.isDirectory()) { final File[] files = root.listFiles(); final String rootName = root.getName(); if(files == null || files.length == 0) { // Create empty directory rollback.add(createRollbackItem(rootName, path, NO_CONTENT, true)); } else { final List<String> newPath = new ArrayList<String>(path); newPath.add(rootName); for (File file : files) { final String name = file.getName(); final File newBackupLocation = new File(backupLocation, name); backup(file, newBackupLocation, newPath, rollback, context); } } } else { // Copy and record the backup action final byte[] hash = copy(root, backupLocation); rollback.add(createRollbackItem(root.getName(), path, hash, false)); } }
@Override byte[] apply(PatchingTaskContext context, PatchContentLoader loader) throws IOException { if (context.getCurrentMode() == PatchingTaskContext.Mode.ROLLBACK) { return getContentItem().getContentHash(); } // Copy the new bundle resources to the patching directory final File targetDir = context.getTargetFile(contentItem); final File sourceDir = loader.getFile(contentItem); final File[] moduleResources = sourceDir.listFiles(); if(! targetDir.mkdirs() && ! targetDir.exists()) { throw PatchLogger.ROOT_LOGGER.cannotCreateDirectory(targetDir.getAbsolutePath()); } if(moduleResources == null || moduleResources.length == 0) { return NO_CONTENT; } for(final File file : moduleResources) { final File target = new File(targetDir, file.getName()); IoUtils.copy(file, target); } return contentItem.getContentHash(); }
@Override byte[] apply(PatchingTaskContext context, PatchContentLoader loader) throws IOException { if (context.getCurrentMode() == PatchingTaskContext.Mode.ROLLBACK) { return getContentItem().getContentHash(); } // Copy the new bundle resources to the patching directory final File targetDir = context.getTargetFile(contentItem); final File sourceDir = loader.getFile(contentItem); final File[] moduleResources = sourceDir.listFiles(); if(! targetDir.mkdirs() && ! targetDir.exists()) { throw PatchLogger.ROOT_LOGGER.cannotCreateDirectory(targetDir.getAbsolutePath()); } if(moduleResources == null || moduleResources.length == 0) { return NO_CONTENT; } for(final File file : moduleResources) { final File target = new File(targetDir, file.getName()); IoUtils.copy(file, target); } return contentItem.getContentHash(); }
@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 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); } } }
IoUtils.copy(zippedOneOff, new File(patchBundleDir, zippedOneOff.getName())); IoUtils.copy(zippedCP, new File(patchBundleDir, zippedCP.getName())); final List<BundledPatch.BundledPatchEntry> bundledPatches = new ArrayList<BundledPatch.BundledPatchEntry>(); bundledPatches.add(new BundledPatch.BundledPatchEntry(patchID, zippedOneOff.getName()));