/** * unpack... * * @param zip the zip * @param patchDir the patch dir * @throws IOException */ public static void unzip(final File zip, final File patchDir) throws IOException { try (final ZipFile zipFile = new ZipFile(zip)){ unzip(zipFile, patchDir); } }
private static void addDirectoryToZip(File dir, String dirName, ZipOutputStream zos) throws IOException { final ZipEntry dirEntry = new ZipEntry(dirName + "/"); zos.putNextEntry(dirEntry); zos.closeEntry(); File[] children = dir.listFiles(); if (children != null) { for (File file : children) { if (file.isDirectory()) { addDirectoryToZip(file, dirName + "/" + file.getName(), zos); } else { addFileToZip(file, dirName, zos); } } } }
public static File createZippedPatchFile(File sourceDir, String zipFileName) { //tree(sourceDir); File zipFile = new File(sourceDir.getParent(), zipFileName + ".zip"); ZipUtils.zip(sourceDir, zipFile); return zipFile; }
ZipUtils.zip(mergedDir, merged); IoUtils.recursiveDelete(workDir); return merged;
ZipUtils.zip(mergedDir, merged); IoUtils.recursiveDelete(workDir); return merged;
/** * unpack... * * @param zip the zip * @param patchDir the patch dir * @throws IOException */ public static void unzip(final File zip, final File patchDir) throws IOException { try (final ZipFile zipFile = new ZipFile(zip)){ unzip(zipFile, patchDir); } }
private static void addDirectoryToZip(File dir, String dirName, ZipOutputStream zos) throws IOException { final ZipEntry dirEntry = new ZipEntry(dirName + "/"); zos.putNextEntry(dirEntry); zos.closeEntry(); File[] children = dir.listFiles(); if (children != null) { for (File file : children) { if (file.isDirectory()) { addDirectoryToZip(file, dirName + "/" + file.getName(), zos); } else { addFileToZip(file, dirName, zos); } } } }
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; }
public static void zip(File sourceDir, File zipFile) { try (final FileOutputStream os = new FileOutputStream(zipFile); final ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(os)) ) { for (final File file : sourceDir.listFiles()) { if (file.isDirectory()) { addDirectoryToZip(file, file.getName(), zos); } else { addFileToZip(file, null, zos); } } } catch (IOException e) { throw new RuntimeException("Failed creating patch file " + zipFile, e); // Only used for generation and tests } }
PatchMerger.merge(previousCp, tmp, patchFile); } else { ZipUtils.zip(tmp, patchFile);
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; }
public static void zip(File sourceDir, File zipFile) { try (final FileOutputStream os = new FileOutputStream(zipFile); final ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(os)) ) { for (final File file : sourceDir.listFiles()) { if (file.isDirectory()) { addDirectoryToZip(file, file.getName(), zos); } else { addFileToZip(file, null, zos); } } } catch (IOException e) { throw new RuntimeException("Failed creating patch file " + zipFile, e); // Only used for generation and tests } }
private PatchingResult applyPatch(final File parentWorkDir, final InputStream is, final ContentVerificationPolicy contentPolicy) throws PatchingException { File workDir = null; try { // Create a working dir workDir = parentWorkDir == null ? IdentityPatchRunner.createTempDir() : IdentityPatchRunner.createTempDir(parentWorkDir); try { // Save the content Path cachedContent = workDir.toPath().resolve("content"); Files.copy(is, cachedContent); // Unpack to the work dir ZipUtils.unzip(cachedContent.toFile(), workDir); } catch (IOException e) { throw PatchLogger.ROOT_LOGGER.cannotCopyFilesToTempDir(workDir.getAbsolutePath(), e.getMessage(), e); // add info that temp dir is involved } // Execute return execute(workDir, contentPolicy); } catch (Exception e) { throw rethrowException(e); } finally { if (workDir != null && !IoUtils.recursiveDelete(workDir)) { PatchLogger.ROOT_LOGGER.cannotDeleteFile(workDir.getAbsolutePath()); } } }
private PatchingResult applyPatch(final File parentWorkDir, final InputStream is, final ContentVerificationPolicy contentPolicy) throws PatchingException { File workDir = null; try { // Create a working dir workDir = parentWorkDir == null ? IdentityPatchRunner.createTempDir() : IdentityPatchRunner.createTempDir(parentWorkDir); try { // Save the content Path cachedContent = workDir.toPath().resolve("content"); Files.copy(is, cachedContent); // Unpack to the work dir ZipUtils.unzip(cachedContent.toFile(), workDir); } catch (IOException e) { throw PatchLogger.ROOT_LOGGER.cannotCopyFilesToTempDir(workDir.getAbsolutePath(), e.getMessage(), e); // add info that temp dir is involved } // Execute return execute(workDir, contentPolicy); } catch (Exception e) { throw rethrowException(e); } finally { if (workDir != null && !IoUtils.recursiveDelete(workDir)) { PatchLogger.ROOT_LOGGER.cannotDeleteFile(workDir.getAbsolutePath()); } } }