FsEntry getEntry(TPath path) throws IOException { return getController().getEntry(path.getEntryName()); }
/** * {@inheritDoc} * * @see <a href="#falsePositives">Detecting Archive Paths and False Positives</a> */ @Override public boolean exists() { // DONT test existance of getEnclFsEntryName() in enclArchive because // it doesn't need to exist - see // http://java.net/jira/browse/TRUEZIP-136 . if (null != innerArchive) { try { FsEntry entry = innerArchive.getController() .getEntry(getInnerFsEntryName()); return null != entry; } catch (IOException ex) { return false; } } return file.exists(); }
final FsEntry entry; try { entry = innerArchive.getController().getEntry(getInnerFsEntryName()); } catch (IOException ex) { return null;
/** * Returns the names of the members in this (virtual) directory in a newly * created array. * The returned array is <em>not</em> sorted. * This is the most efficient list method. * <p> * <b>Note:</b> Archive entries with absolute paths are ignored by * this method and are never returned. * * @return A possibly empty array with the members of this (virtual) * directory or {@code null} if this instance does not refer to a * (virtual) directory or if the virtual directory is inaccessible * due to an I/O failure. */ @Override public @Nullable String[] list() { if (null != innerArchive) { final FsEntry entry; try { entry = innerArchive.getController().getEntry(getInnerFsEntryName()); } catch (IOException ex) { return null; } if (null == entry) return null; final Set<String> members = entry.getMembers(); return null == members ? null : members.toArray(new String[members.size()]); } return file.list(); }
FsEntryAttributes(final TPath path) throws IOException { if (null == (entry = getController().getEntry(path.getEntryName()))) throw new NoSuchFileException(path.toString()); }
/** * Similar to its super class implementation, but returns * {@code true} for a valid archive file, too. * <p> * For archive file validation its virtual file system gets mounted. * In case a RAES encrypted ZIP file gets mounted, the user gets prompted * for its password unless the default configuration for key management * hasn't been overridden. * * @see <a href="#falsePositives">Detecting Archive Paths and False Positives</a> * @see #isArchive * @see #isEntry */ @Override public boolean isDirectory() { if (null != innerArchive) { try { FsEntry entry = innerArchive.getController() .getEntry(getInnerFsEntryName()); return null != entry && entry.isType(DIRECTORY); } catch (IOException ex) { return false; } } return file.isDirectory(); }
/** * Returns a {@code long} value representing the time this file was * last modified, measured in milliseconds since the epoch (00:00:00 GMT, * January 1, 1970), or {@code 0L} if the file does not exist or if an * I/O error occurs or if this is a ghost directory in an archive file. * * @see <a href="package.html">Package description for more information * about ghost directories</a> */ @Override public long lastModified() { if (null != innerArchive) { final FsEntry entry; try { entry = innerArchive.getController().getEntry(getInnerFsEntryName()); } catch (IOException ex) { return 0; } if (null == entry) return 0; final long time = entry.getTime(Access.WRITE); return UNKNOWN != time ? time : 0; } return file.lastModified(); }
/** * Similar to its super class implementation, but returns * {@code false} for a valid archive file, too. * <p> * For archive file validation its virtual file system gets mounted. * In case a RAES encrypted ZIP file gets mounted, the user gets prompted * for its password unless the default configuration for key management * hasn't been overridden. * * @see <a href="#falsePositives">Detecting Archive Paths and False Positives</a> */ @Override public boolean isFile() { if (null != innerArchive) { try { FsEntry entry = innerArchive.getController() .getEntry(getInnerFsEntryName()); return null != entry && entry.isType(FILE); } catch (IOException ex) { return false; } } return file.isFile(); }
/** * Returns the (uncompressed) length of the file. * The length returned of a valid archive file is {@code 0} in order * to properly emulate virtual directories across all platforms. * <p> * For archive file validation its virtual file system gets mounted. * In case a RAES encrypted ZIP file gets mounted, the user gets prompted * for its password unless the default configuration for key management * hasn't been overridden. * * @see <a href="#falsePositives">Detecting Archive Paths and False Positives</a> */ @Override public long length() { if (null != innerArchive) { final FsEntry entry; try { entry = innerArchive.getController().getEntry(getInnerFsEntryName()); } catch (IOException ex) { return 0; } if (null == entry) return 0; final long size = entry.getSize(Size.DATA); return UNKNOWN != size ? size : 0; } return file.length(); }
final FsEntry entry; try { entry = innerArchive.getController().getEntry(getInnerFsEntryName()); } catch (IOException ex) { return null;
final FsEntry entry; try { entry = innerArchive.getController().getEntry(getInnerFsEntryName()); } catch (IOException ex) { return null;
null); } catch (IOException ex) { final FsEntry entry = controller.getEntry(innerEntryName); if (null == entry || !entry.isType(DIRECTORY)) throw ex;
/** * Creates a new, empty file similar to its superclass implementation. * Note that this method doesn't create archive files because archive * files are virtual directories, not files! * * @see #mkdir */ @Override public boolean createNewFile() throws IOException { if (null != innerArchive) { final FsController<?> controller = innerArchive.getController(); final FsEntryName entryName = getInnerFsEntryName(); // FIXME: This is not properly isolated. if (null != controller.getEntry(entryName)) return false; controller.mknod( entryName, FILE, TConfig.get().getOutputPreferences().set(EXCLUSIVE), null); return true; } return file.createNewFile(); }
void createDirectory(final TPath path, final FileAttribute<?>... attrs) throws IOException { if (0 < attrs.length) throw new UnsupportedOperationException(); final FsController<?> controller = getController(); final FsEntryName name = path.getEntryName(); try { controller.mknod( name, DIRECTORY, path.getOutputPreferences(), null); } catch (IOException ex) { if (null != controller.getEntry(name)) throw (IOException) new FileAlreadyExistsException(path.toString()) .initCause(ex); throw ex; } }
@Override public FsEntry getEntry(final FsEntryName name) throws IOException { try { return delegate.getEntry(name); } catch (final ControlFlowException ex) { if (!name.isRoot() || null == findKeyException(ex)) throw ex; Entry entry = getParent().getEntry( getModel() .getMountPoint() .getPath() .resolve(name) .getEntryName()); // We're not holding any locks, so it's possible that someone else // has concurrently modified the parent file system. if (null == entry) return null; // The entry is inaccessible for some reason. // This may be because the cipher key is not available. // Now mask the entry as a special file. while (entry instanceof FsCovariantEntry<?>) entry = ((FsCovariantEntry<?>) entry).getEntry(); final FsCovariantEntry<FsArchiveEntry> special = new FsCovariantEntry<FsArchiveEntry>(ROOT_PATH); special.put(SPECIAL, driver.newEntry(ROOT_PATH, SPECIAL, entry)); return special; } }
SeekableByteChannel newByteChannel( final TPath path, final Set<? extends OpenOption> options, final FileAttribute<?>... attrs) throws IOException { final FsEntryName name = path.getEntryName(); final FsController<?> controller = getController(); if (options.isEmpty() || options.contains(StandardOpenOption.READ)) { final BitField<FsInputOption> o = path.mapInput(options).set(FsInputOption.CACHE); return controller .getInputSocket(name, o) .newSeekableByteChannel(); } else { final BitField<FsOutputOption> o = path.mapOutput(options).set(FsOutputOption.CACHE); try { return controller .getOutputSocket(name, o, null) .newSeekableByteChannel(); } catch (final IOException ex) { if (o.get(EXCLUSIVE) && null != controller.getEntry(name)) throw (IOException) new FileAlreadyExistsException(path.toString()) .initCause(ex); throw ex; } } }
void checkAccess(final TPath path, final AccessMode... modes) throws IOException { final FsEntryName name = path.getEntryName(); final FsController<?> controller = getController(); if (null == controller.getEntry(name)) throw new NoSuchFileException(path.toString()); for (final AccessMode m : modes) { switch (m) { case READ: if (!controller.isReadable(name)) throw new AccessDeniedException(path.toString()); break; case WRITE: if (!controller.isWritable(name)) throw new AccessDeniedException(path.toString()); break; case EXECUTE: if (!controller.isExecutable(name)) throw new AccessDeniedException(path.toString()); break; default: throw new UnsupportedOperationException(); } } }