public void testImplicitPermissions() throws IOException { File zipFile = getTestFile("target/output/zip-with-implicit-dirmode.zip"); ZipArchiver archiver = getZipArchiver(zipFile); archiver.setDefaultDirectoryMode(0777); archiver.setDirectoryMode(0641); archiver.setFileMode(0222); archiver.addFile(new File("pom.xml"), "fizz/buzz/pom.xml"); archiver.setDefaultDirectoryMode(0530); archiver.setDirectoryMode(-1); // Not forced mode archiver.setFileMode(0111); archiver.addFile(new File("pom.xml"), "fazz/bazz/pam.xml"); archiver.createArchive(); assertTrue(zipFile.exists()); ZipFile zf = new ZipFile(zipFile); ZipArchiveEntry fizz = zf.getEntry("fizz/"); assertEquals(040641, fizz.getUnixMode()); ZipArchiveEntry pom = zf.getEntry("fizz/buzz/pom.xml"); assertEquals(0100222, pom.getUnixMode()); ZipArchiveEntry fazz = zf.getEntry("fazz/"); assertEquals(040530, fazz.getUnixMode()); ZipArchiveEntry pam = zf.getEntry("fazz/bazz/pam.xml"); assertEquals(0100111, pam.getUnixMode()); }
private ZipArchiver newArchiver(String name) throws Exception { ZipArchiver archiver = getZipArchiver(getTestFile("target/output/" + name)); archiver.setFileMode(0640); archiver.addFile(getTestFile("src/test/resources/manifests/manifest1.mf"), "one.txt"); archiver.addFile(getTestFile("src/test/resources/manifests/manifest2.mf"), "two.txt", 0664); // reset default file mode for files included from now on archiver.setFileMode(0400); archiver.setDirectoryMode(0777); archiver.addDirectory(getTestFile("src/test/resources/world-writable/"), "worldwritable/"); archiver.setDirectoryMode(0070); archiver.addDirectory(getTestFile("src/test/resources/group-writable/"), "groupwritable/"); archiver.setDirectoryMode(0500); archiver.setFileMode(0400); archiver.addDirectory(getTestFile("src")); return archiver; }