@Override public FilePermissions getPermissions() { // Return the entry's permissions return entry.getPermissions(); }
@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 returns a {@link com.mucommander.commons.file.archive.zip.provider.ZipEntry} instance using the attributes * of the given {@link ArchiveEntry}. * * @param entry the object that serves to initialize the attributes of the returned ZipEntry * @return a ZipEntry whose attributes are fetched from the given ZipEntry */ private ZipEntry createZipEntry(ArchiveEntry entry) { boolean isDirectory = entry.isDirectory(); String path = entry.getPath(); if(isDirectory && !path.endsWith("/")) path += "/"; com.mucommander.commons.file.archive.zip.provider.ZipEntry zipEntry = new com.mucommander.commons.file.archive.zip.provider.ZipEntry(path); zipEntry.setMethod(ZipConstants.DEFLATED); zipEntry.setTime(System.currentTimeMillis()); zipEntry.setUnixMode(SimpleFilePermissions.padPermissions(entry.getPermissions(), isDirectory ? FilePermissions.DEFAULT_DIRECTORY_PERMISSIONS : FilePermissions.DEFAULT_FILE_PERMISSIONS).getIntValue()); return zipEntry; }
@Override public void updateEntry(ArchiveEntry entry) throws IOException, UnsupportedFileOperationException { ZipEntry zipEntry = (com.mucommander.commons.file.archive.zip.provider.ZipEntry)entry.getEntryObject(); // Most of the time, the ZipEntry will not be null. However, it can be null in some rare cases, when directory // entries have been created in the entries tree but don't exist in the Zip file. // That is the case when a file entry exists in the Zip file but has no directory entry for the parent. if(zipEntry!=null) { // Entry exists physically in the zip file checkZipFile(); zipEntry.setTime(entry.getDate()); zipEntry.setUnixMode(entry.getPermissions().getIntValue()); // Physically update the entry's attributes in the Zip file zipFile.updateEntry(zipEntry); // Declare the zip file and entries tree up-to-date declareZipFileUpToDate(); declareEntriesTreeUpToDate(); } }