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; }
public void testOverddidenPermissions() throws IOException { File zipFile = getTestFile("target/output/zip-with-overriden-modes.zip"); ZipArchiver archiver = getZipArchiver(zipFile); archiver.setDefaultDirectoryMode(0777); archiver.setDirectoryMode(0641); archiver.setFileMode(0777); archiver.addDirectory(new File("src/test/resources/symlinks/src")); archiver.createArchive(); assertTrue(zipFile.exists()); ZipFile zf = new ZipFile(zipFile); ZipArchiveEntry fizz = zf.getEntry("symDir"); assertTrue(fizz.isUnixSymlink()); ZipArchiveEntry symR = zf.getEntry("symR"); assertTrue(symR.isUnixSymlink()); }
public void testForcedFileModes() throws IOException { File step1file = new File("target/output/forced-file-mode.zip"); { final ZipArchiver zipArchiver = getZipArchiver(step1file); zipArchiver.setFileMode(0077); zipArchiver.setDirectoryMode(0007); PlexusIoResourceAttributes attrs = new SimpleResourceAttributes(123, "fred", 22, "filntstones", 0111); PlexusIoResource resource = ResourceFactory.createResource( new File("src/test/resources/folders/File.txt"), "Test.txt", null, attrs); zipArchiver.addResource(resource, "Test2.txt", 0707); PlexusIoFileResourceCollection files = new PlexusIoFileResourceCollection(); files.setBaseDir(new File("src/test/resources/folders")); files.setPrefix("sixsixsix/"); zipArchiver.addResources(files); zipArchiver.createArchive(); ZipFile zf = new ZipFile(step1file); fileModeAssert(040007, zf.getEntry("sixsixsix/a/").getUnixMode()); fileModeAssert(0100077, zf.getEntry("sixsixsix/b/FileInB.txt").getUnixMode()); fileModeAssert(0100707, zf.getEntry("Test2.txt").getUnixMode()); zf.close(); } File Step2file = new File("target/output/forced-file-mode-from-zip.zip"); { final ZipArchiver za2 = getZipArchiver(Step2file); za2.setFileMode(0666); za2.setDirectoryMode(0676); PlexusIoZipFileResourceCollection zipSrc = new PlexusIoZipFileResourceCollection(); zipSrc.setFile(step1file); zipSrc.setPrefix("zz/"); za2.addResources(zipSrc); za2.createArchive(); ZipFile zf = new ZipFile(Step2file); fileModeAssert(040676, zf.getEntry("zz/sixsixsix/a/").getUnixMode()); fileModeAssert(0100666, zf.getEntry("zz/Test2.txt").getUnixMode()); zf.close(); } File step3file = new File("target/output/forced-file-mode-from-zip2.zip"); { final ZipArchiver za2 = getZipArchiver(step3file); za2.setFileMode(0666); za2.setDirectoryMode(0676); PlexusArchiverZipFileResourceCollection zipSrc = new PlexusArchiverZipFileResourceCollection(); zipSrc.setFile(step1file); zipSrc.setPrefix("zz/"); za2.addResources(zipSrc); za2.createArchive(); ZipFile zf = new ZipFile(Step2file); fileModeAssert(040676, zf.getEntry("zz/sixsixsix/a/").getUnixMode()); fileModeAssert(0100666, zf.getEntry("zz/Test2.txt").getUnixMode()); zf.close(); } }