public void testZipNonConcurrentResourceCollection() throws Exception { final File tarFile = getTestFile("target/output/zip-non-concurrent.tar"); TarArchiver tarArchiver = (TarArchiver) lookup(Archiver.ROLE, "tar"); tarArchiver.setDestFile(tarFile); // We're testing concurrency issue so we need large amount of files for (int i = 0; i < 100; i++) { tarArchiver.addFile( getTestFile("src/test/resources/manifests/manifest1.mf"), "manifest1.mf" + i); // Directories are added separately so let's test them too tarArchiver.addFile( getTestFile("src/test/resources/manifests/manifest2.mf"), "subdir" + i + "/manifest2.mf"); } tarArchiver.createArchive(); final File zipFile = new File("target/output/zip-non-concurrent.zip"); ZipArchiver zipArchive = getZipArchiver(zipFile); zipArchive.addArchivedFileSet(tarFile, "prfx/"); zipArchive.setEncoding("UTF-8"); zipArchive.createArchive(); final TarFile cmp1 = new TarFile(tarFile); final ZipFile cmp2 = new ZipFile(zipFile); ArchiveFileComparator.assertEquals(cmp1, cmp2, "prfx/"); cmp1.close(); cmp2.close(); }
private Archiver createArchiver() { if (isZip()) { return new ZipArchiver(); } final TarArchiver archiver = new TarArchiver(); final TarArchiver.TarCompressionMethod tarCompressionMethod = new TarArchiver.TarCompressionMethod(); tarCompressionMethod.setValue("gzip"); archiver.setCompression(tarCompressionMethod); return archiver; }
@Override public TarArchiver customize(TarArchiver archiver) throws IOException { log.warn("/--------------------- SECURITY WARNING ---------------------\\"); log.warn("|You are building a Docker image with normalized permissions.|"); log.warn("|All files and directories added to build context will have |"); log.warn("|'-rwxr-xr-x' permissions. It is recommended to double check |"); log.warn("|and reset permissions for sensitive files and directories. |"); log.warn("\\------------------------------------------------------------/"); if (innerCustomizer != null) { archiver = innerCustomizer.customize(archiver); } TarArchiver newArchiver = new TarArchiver(); newArchiver.setDestFile(archiver.getDestFile()); newArchiver.setLongfile(TarLongFileMode.posix); ResourceIterator resources = archiver.getResources(); while (resources.hasNext()) { ArchiveEntry ae = resources.next(); String fileName = ae.getName(); PlexusIoResource resource = ae.getResource(); String name = StringUtils.replace(fileName, File.separatorChar, '/'); // See docker source: // https://github.com/docker/docker/blob/3d13fddd2bc4d679f0eaa68b0be877e5a816ad53/pkg/archive/archive_windows.go#L45 int mode = ae.getMode() & 0777; int newMode = mode; newMode &= 0755; newMode |= 0111; if (newMode != mode) { log.debug("Changing permissions of '%s' from %o to %o.", name, mode, newMode); } newArchiver.addResource(resource, name, newMode); } archiver = newArchiver; return archiver; }