@Override public void changePermissions(int permissions) throws IOException { if(!entry.exists()) throw new IOException(); FilePermissions oldPermissions = entry.getPermissions(); FilePermissions newPermissions = new SimpleFilePermissions(permissions, oldPermissions.getMask()); entry.setPermissions(newPermissions); boolean success = updateEntryAttributes(); if(!success) // restore old permissions if attributes could not be updated entry.setPermissions(oldPermissions); if(!success) throw new IOException(); } }
/** * Creates and return an {@link ArchiveEntry()} whose attributes are fetched from the given * <code>org.apache.tools.tar.TarEntry</code>. * * @param tarEntry the object that serves to initialize the attributes of the returned ArchiveEntry * @return an ArchiveEntry whose attributes are fetched from the given org.apache.tools.tar.TarEntry */ private ArchiveEntry createArchiveEntry(TarEntry tarEntry) { ArchiveEntry entry = new ArchiveEntry(tarEntry.getName(), tarEntry.isDirectory(), tarEntry.getModTime().getTime(), tarEntry.getSize(), true); entry.setPermissions(new SimpleFilePermissions(tarEntry.getMode() & PermissionBits.FULL_PERMISSION_INT)); entry.setOwner(tarEntry.getUserName()); entry.setGroup(tarEntry.getGroupName()); entry.setEntryObject(tarEntry); return entry; }
/** * Creates and return an {@link ArchiveEntry()} whose attributes are fetched from the given {@link com.mucommander.commons.file.archive.zip.provider.ZipEntry}. * It is worth noting that the returned entry has the {@link ArchiveEntry#exists exists} flag set to <code>true</code>. * * @param zipEntry the object that serves to initialize the attributes of the returned ArchiveEntry * @return an ArchiveEntry whose attributes are fetched from the given ZipEntry */ static ArchiveEntry createArchiveEntry(ZipEntry zipEntry) { ArchiveEntry entry = new ArchiveEntry(zipEntry.getName(), zipEntry.isDirectory(), zipEntry.getTime(), zipEntry.getSize(), true); if(zipEntry.hasUnixMode()) entry.setPermissions(new SimpleFilePermissions(zipEntry.getUnixMode())); entry.setEntryObject(zipEntry); return entry; }