/** * <p>In case it's impossible to determine the actual permissions, returns an "always-true" permission.</p> * * @param checkIds * @return * @throws Exception */ @Override protected PosixPermissions getPermissions( boolean checkIds ) throws Exception { if ( checkIds && ( getAbstractFileSystem() instanceof SftpFileSystemWindows ) && ( (SftpFileSystemWindows) getAbstractFileSystem() ).isExecDisabled() ) { // Exec is disabled, so we won't be able to ascertain the current user's UID and GID. // Return "always-true" permissions as a workaround, knowing that the SFTP server won't // let us perform unauthorized actions anyway. return new PretendUserIsOwnerPosixPermissions(); } return super.getPermissions( checkIds ); }
/** * Creates a file object. This method is called only if the requested file is not cached. */ @Override protected FileObject createFile(final AbstractFileName name) throws FileSystemException { return new SftpFileObject(name, this); }
protected FileObject[] doListChildrenResolved() throws Exception { if (this.isFile()) { return null; final ChannelSftp channel = getAbstractFileSystem().getChannel(); getAbstractFileSystem().putChannel(channel); final FileObject fo = getFileSystem().resolveFile(getFileSystem().getFileSystemManager() .resolveName(getName(), UriParser.encode(name), NameScope.CHILD)); ((SftpFileObject) FileObjectUtils.getAbstractFileObject(fo)).setStat(stat.getAttrs());
@Override protected boolean doSetExecutable(final boolean executable, final boolean ownerOnly) throws Exception { final PosixPermissions permissions = getPermissions(false); final int newPermissions = permissions.makeExecutable(executable, ownerOnly); if (newPermissions == permissions.getPermissions()) { return true; } attrs.setPERMISSIONS(newPermissions); flushStat(); return true; }
protected InputStream doGetInputStream() throws Exception { synchronized (getAbstractFileSystem()) { final ChannelSftp channel = getAbstractFileSystem().getChannel(); try { if (!getType().hasContent()) { throw new FileSystemException("vfs.provider/read-not-file.error", getName()); } catch (final SftpException e) { if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) { throw new FileNotFoundException(getName());
private void flushStat() throws IOException, SftpException { final ChannelSftp channel = getAbstractFileSystem().getChannel(); try { channel.setStat(relPath, attrs); } finally { getAbstractFileSystem().putChannel(channel); } }
/** * Return the destination of this file object if it's a symbolic link * * @return FileObject representing the linked to location */ @Override public SftpFileObject getLinkDestination() throws Exception { if (linkDestination == null) { final ChannelSftp channel = getAbstractFileSystem().getChannel(); try { final String path = channel.readlink(relPath); FileName relativeTo = getName().getParent(); if (relativeTo == null) { relativeTo = getName(); } FileName linkDestinationName = getFileSystem().getFileSystemManager().resolveName(relativeTo, path); linkDestination = (SftpFileObject) getFileSystem().resolveFile(linkDestinationName); } finally { getAbstractFileSystem().putChannel(channel); } } return linkDestination; } // [IntelliJ] WI-5627 --------------
/** * Deletes the file. */ @Override protected void doDelete() throws Exception { final ChannelSftp channel = getAbstractFileSystem().getChannel(); try { if (isFile()) { channel.rm(relPath); } else { channel.rmdir(relPath); } } finally { getAbstractFileSystem().putChannel(channel); } }
/** * Creates an input stream to read the file content from. The input stream is starting at the given position in the * file. */ InputStream getInputStream(final long filePointer) throws IOException { final ChannelSftp channel = getAbstractFileSystem().getChannel(); // Using InputStream directly from the channel // is much faster than the memory method. try { final InputStream is = channel.get(getName().getPathDecoded(), null, filePointer); return new SftpInputStream(channel, is); } catch (final SftpException e) { getAbstractFileSystem().putChannel(channel); throw new FileSystemException(e); } }
/** * Returns the POSIX type permissions of the file. * * @param checkIds {@code true} if user and group ID should be checked (needed for some access rights checks) * @return A PosixPermission object * @throws Exception If an error occurs * @since 2.1 */ protected PosixPermissions getPermissions(final boolean checkIds) throws Exception { statSelf(); boolean isInGroup = false; if (checkIds) { for (final int groupId : getAbstractFileSystem().getGroupsIds()) { if (groupId == attrs.getGId()) { isInGroup = true; break; } } } final boolean isOwner = checkIds ? attrs.getUId() == getAbstractFileSystem().getUId() : false; return new PosixPermissions(attrs.getPermissions(), isOwner, isInGroup); }
ChannelSftp channel = getAbstractFileSystem().getChannel(); try { setStat(channel.stat(relPath)); } catch (final SftpException e) { try { channel = getAbstractFileSystem().getChannel(); setStat(channel.stat(relPath)); } else { getAbstractFileSystem().putChannel(channel);
statSelf(); SftpFileObject fileObject = this; while(i < max){ fileObject = fileObject.getLinkDestination(); if (fileObject.attrs == null) fileObject.statSelf(); return fileObject.getType(); } else { i++;
@Override public long length() throws IOException { return fileObject.getContent().getSize(); } }
/** * Sets the last modified time of this file. Is only called if {@link #doGetType} does not return * {@link FileType#IMAGINARY}. * * @param modtime is modification time in milliseconds. SFTP protocol can send times with nanosecond precision but * at the moment jsch send them with second precision. */ @Override protected boolean doSetLastModifiedTime(final long modtime) throws Exception { final int newMTime = (int) (modtime / MOD_TIME_FACTOR); attrs.setACMODTIME(attrs.getATime(), newMTime); flushStat(); return true; }
/** * @throws FileSystemException if error occurs. * @since 2.0 */ @Override public void refresh() throws FileSystemException { if (!inRefresh) { try { inRefresh = true; super.refresh(); try { attrs = null; getType(); } catch (final IOException e) { throw new FileSystemException(e); } } finally { inRefresh = false; } } }
mis = fileObject.getInputStream(filePointer); dis = new DataInputStream(new FilterInputStream(mis) { @Override
protected FileObject[] doListChildrenResolved() throws Exception { if (this.isFile()) { return null; final ChannelSftp channel = getAbstractFileSystem().getChannel(); getAbstractFileSystem().putChannel(channel); final FileObject fo = getFileSystem().resolveFile(getFileSystem().getFileSystemManager() .resolveName(getName(), UriParser.encode(name), NameScope.CHILD)); ((SftpFileObject) FileObjectUtils.getAbstractFileObject(fo)).setStat(stat.getAttrs());
@Override protected boolean doSetWritable(final boolean writable, final boolean ownerOnly) throws Exception { final PosixPermissions permissions = getPermissions(false); final int newPermissions = permissions.makeWritable(writable, ownerOnly); if (newPermissions == permissions.getPermissions()) { return true; } attrs.setPERMISSIONS(newPermissions); flushStat(); return true; }
protected InputStream doGetInputStream() throws Exception { synchronized (getAbstractFileSystem()) { final ChannelSftp channel = getAbstractFileSystem().getChannel(); try { if (!getType().hasContent()) { throw new FileSystemException("vfs.provider/read-not-file.error", getName()); } catch (final SftpException e) { if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) { throw new FileNotFoundException(getName());
/** * Creates this file as a folder. */ @Override protected void doCreateFolder() throws Exception { final ChannelSftp channel = getAbstractFileSystem().getChannel(); try { channel.mkdir(relPath); } finally { getAbstractFileSystem().putChannel(channel); } }