protected static void copyDir(File src, File trg) throws PatchingException { try { IoUtils.copyFile(src, trg); } catch (IOException e) { throw new PatchingException("Failed to copy modification content from " + src.getAbsolutePath() + " to " + trg.getAbsolutePath(), e); } }
protected static void copyDir(File src, File trg) throws PatchingException { try { IoUtils.copyFile(src, trg); } catch (IOException e) { throw new PatchingException("Failed to copy modification content from " + src.getAbsolutePath() + " to " + trg.getAbsolutePath(), e); } }
private static void copyDir(File sourceDir, File targetDir) throws IOException { if (targetDir.exists()) { if (!targetDir.isDirectory()) { throw PatchLogger.ROOT_LOGGER.notADirectory(targetDir.getAbsolutePath()); } } else if (!targetDir.mkdirs()) { throw PatchLogger.ROOT_LOGGER.cannotCreateDirectory(targetDir.getAbsolutePath()); } File[] children = sourceDir.listFiles(); if (children != null) { for (File child : children) { copyFile(child, new File(targetDir, child.getName())); } } }
/** * Backup all xml files in a given directory. * * @param source the source directory * @param target the target directory * @throws IOException for any error */ static void backupDirectory(final File source, final File target) throws IOException { if (!target.exists()) { if (!target.mkdirs()) { throw PatchLogger.ROOT_LOGGER.cannotCreateDirectory(target.getAbsolutePath()); } } final File[] files = source.listFiles(CONFIG_FILTER); for (final File file : files) { final File t = new File(target, file.getName()); IoUtils.copyFile(file, t); } }
private static void copyDir(File sourceDir, File targetDir) throws IOException { if (targetDir.exists()) { if (!targetDir.isDirectory()) { throw PatchLogger.ROOT_LOGGER.notADirectory(targetDir.getAbsolutePath()); } } else if (!targetDir.mkdirs()) { throw PatchLogger.ROOT_LOGGER.cannotCreateDirectory(targetDir.getAbsolutePath()); } File[] children = sourceDir.listFiles(); if (children != null) { for (File child : children) { copyFile(child, new File(targetDir, child.getName())); } } }
/** * Backup all xml files in a given directory. * * @param source the source directory * @param target the target directory * @throws IOException for any error */ static void backupDirectory(final File source, final File target) throws IOException { if (!target.exists()) { if (!target.mkdirs()) { throw PatchLogger.ROOT_LOGGER.cannotCreateDirectory(target.getAbsolutePath()); } } final File[] files = source.listFiles(CONFIG_FILTER); for (final File file : files) { final File t = new File(target, file.getName()); IoUtils.copyFile(file, t); } }
@Override byte[] apply(PatchingTaskContext context, PatchContentLoader loader) throws IOException { // Copy the new module resources to the patching directory final File targetDir = context.getTargetFile(contentItem); final File sourceDir = loader.getFile(contentItem); if(sourceDir.exists()) { // Recursively copy module contents (incl. native libs) IoUtils.copyFile(sourceDir, targetDir); } else { // ADD an absent module // this situation happens when merging ADD and REMOVE modifications // which results in an ADD of an absent module if(!targetDir.exists() && ! targetDir.mkdirs()) { throw PatchLogger.ROOT_LOGGER.cannotCreateDirectory(targetDir.getAbsolutePath()); } final Path moduleXml = targetDir.toPath().resolve(MODULE_XML); final ByteArrayInputStream is = new ByteArrayInputStream(PatchUtils.getAbsentModuleContent(contentItem)); Files.copy(is, moduleXml, StandardCopyOption.REPLACE_EXISTING); } // return contentItem.getContentHash(); return HashUtils.hashFile(targetDir); }
@Override byte[] apply(PatchingTaskContext context, PatchContentLoader loader) throws IOException { // Copy the new module resources to the patching directory final File targetDir = context.getTargetFile(contentItem); final File sourceDir = loader.getFile(contentItem); if(sourceDir.exists()) { // Recursively copy module contents (incl. native libs) IoUtils.copyFile(sourceDir, targetDir); } else { // ADD an absent module // this situation happens when merging ADD and REMOVE modifications // which results in an ADD of an absent module if(!targetDir.exists() && ! targetDir.mkdirs()) { throw PatchLogger.ROOT_LOGGER.cannotCreateDirectory(targetDir.getAbsolutePath()); } final Path moduleXml = targetDir.toPath().resolve(MODULE_XML); final ByteArrayInputStream is = new ByteArrayInputStream(PatchUtils.getAbsentModuleContent(contentItem)); Files.copy(is, moduleXml, StandardCopyOption.REPLACE_EXISTING); } // return contentItem.getContentHash(); return HashUtils.hashFile(targetDir); }
/** * 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); } }
IoUtils.copyFile(patch, patchTarget); i++;