http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpFileStore.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpFileStore.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpFileStore.java index 14d43ae..2862b2d 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpFileStore.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpFileStore.java @@ -77,7 +77,7 @@ public class SftpFileStore extends FileStore { @Override public boolean supportsFileAttributeView(Class<? extends FileAttributeView> type) { - SftpFileSystem sftpFs = getFileSystem(); + SftpFileSystem sftpFs = getFileSystem(); SftpFileSystemProvider provider = sftpFs.provider(); return provider.isSupportedFileAttributeView(type); } @@ -87,14 +87,10 @@ public class SftpFileStore extends FileStore { if (GenericUtils.isEmpty(name)) { return false; // debug breakpoint } - - FileSystem sftpFs = getFileSystem(); + + FileSystem sftpFs = getFileSystem(); Collection<String> views = sftpFs.supportedFileAttributeViews(); - if (GenericUtils.isEmpty(views) || (!views.contains(name))) { - return false; // debug breakpoint - } else { - return true; - } + return !GenericUtils.isEmpty(views) && views.contains(name); } @Override
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystem.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystem.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystem.java index 2b3a922..444082c 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystem.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystem.java @@ -47,13 +47,13 @@ import org.apache.sshd.common.util.buffer.Buffer; public class SftpFileSystem extends BaseFileSystem<SftpPath> { public static final String POOL_SIZE_PROP = "sftp-fs-pool-size"; - public static final int DEFAULT_POOL_SIZE = 8; + public static final int DEFAULT_POOL_SIZE = 8; public static final Set<String> SUPPORTED_VIEWS = Collections.unmodifiableSet( GenericUtils.asSortedSet(String.CASE_INSENSITIVE_ORDER, Arrays.asList( - "basic", "posix", "owner" + "basic", "posix", "owner" ))); private final String id; @@ -156,7 +156,7 @@ public class SftpFileSystem extends BaseFileSystem<SftpPath> { String fsId = getId(); SftpFileSystem fs = provider.removeFileSystem(fsId); session.close(true); - + if ((fs != null) && (fs != this)) { throw new FileSystemException(fsId, fsId, "Mismatched FS instance for id=" + fsId); } @@ -183,11 +183,12 @@ public class SftpFileSystem extends BaseFileSystem<SftpPath> { return defaultDir; } - private class Wrapper extends AbstractSftpClient { + private final class Wrapper extends AbstractSftpClient { private final SftpClient delegate; private final AtomicInteger count = new AtomicInteger(1); - private final int readSize, writeSize; + private final int readSize; + private final int writeSize; private Wrapper(SftpClient delegate, int readSize, int writeSize) { this.delegate = delegate; @@ -217,11 +218,7 @@ public class SftpFileSystem extends BaseFileSystem<SftpPath> { @Override public boolean isOpen() { - if (count.get() > 0) { - return true; - } else { - return false; // debug breakpoint - } + return count.get() > 0; } @SuppressWarnings("synthetic-access") @@ -466,7 +463,7 @@ public class SftpFileSystem extends BaseFileSystem<SftpPath> { if (!isOpen()) { throw new IOException("send(cmd=" + cmd + ") client is closed"); } - + if (delegate instanceof RawSftpClient) { return ((RawSftpClient) delegate).send(cmd, buffer); } else { @@ -479,7 +476,7 @@ public class SftpFileSystem extends BaseFileSystem<SftpPath> { if (!isOpen()) { throw new IOException("receive(id=" + id + ") client is closed"); } - + if (delegate instanceof RawSftpClient) { return ((RawSftpClient) delegate).receive(id); } else { @@ -519,8 +516,12 @@ public class SftpFileSystem extends BaseFileSystem<SftpPath> { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } DefaultUserPrincipal that = (DefaultUserPrincipal) o; return name.equals(that.name); } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemProvider.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemProvider.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemProvider.java index b0ecafc..9bba23e 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemProvider.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemProvider.java @@ -83,13 +83,13 @@ import org.slf4j.LoggerFactory; public class SftpFileSystemProvider extends FileSystemProvider { public static final String READ_BUFFER_PROP_NAME = "sftp-fs-read-buffer-size"; - public static final int DEFAULT_READ_BUFFER_SIZE = SftpClient.DEFAULT_READ_BUFFER_SIZE; + public static final int DEFAULT_READ_BUFFER_SIZE = SftpClient.DEFAULT_READ_BUFFER_SIZE; public static final String WRITE_BUFFER_PROP_NAME = "sftp-fs-write-buffer-size"; - public static final int DEFAULT_WRITE_BUFFER_SIZE = SftpClient.DEFAULT_WRITE_BUFFER_SIZE; + public static final int DEFAULT_WRITE_BUFFER_SIZE = SftpClient.DEFAULT_WRITE_BUFFER_SIZE; public static final String CONNECT_TIME_PROP_NAME = "sftp-fs-connect-time"; - public static final long DEFAULT_CONNECT_TIME = SftpClient.DEFAULT_WAIT_TIMEOUT; + public static final long DEFAULT_CONNECT_TIME = SftpClient.DEFAULT_WAIT_TIMEOUT; public static final String AUTH_TIME_PROP_NAME = "sftp-fs-auth-time"; - public static final long DEFAULT_AUTH_TIME = SftpClient.DEFAULT_WAIT_TIMEOUT; + public static final long DEFAULT_AUTH_TIME = SftpClient.DEFAULT_WAIT_TIMEOUT; public static final Set<Class<? extends FileAttributeView>> SUPPORTED_VIEWS = Collections.unmodifiableSet( @@ -98,10 +98,11 @@ public class SftpFileSystemProvider extends FileSystemProvider { BasicFileAttributeView.class, PosixFileAttributeView.class ))); + protected final Logger log; + private final SshClient client; private final SftpVersionSelector selector; private final Map<String, SftpFileSystem> fileSystems = new HashMap<String, SftpFileSystem>(); - protected final Logger log; public SftpFileSystemProvider() { this((SshClient) null); @@ -113,8 +114,8 @@ public class SftpFileSystemProvider extends FileSystemProvider { /** * @param client The {@link SshClient} to use - if {@code null} then a - * default one will be setup and started. Otherwise, it is assumed that - * the client has already been started + * default one will be setup and started. Otherwise, it is assumed that + * the client has already been started * @see SshClient#setUpDefaultClient() */ public SftpFileSystemProvider(SshClient client) { @@ -152,32 +153,32 @@ public class SftpFileSystemProvider extends FileSystemProvider { String userInfo = ValidateUtils.checkNotNullAndNotEmpty(uri.getUserInfo(), "UserInfo not provided"); String[] ui = GenericUtils.split(userInfo, ':'); ValidateUtils.checkTrue(GenericUtils.length(ui) == 2, "Invalid user info: %s", userInfo); - String username = ui[0], password = ui[1]; + String username = ui[0]; + String password = ui[1]; String id = getFileSystemIdentifier(host, port, username); SftpFileSystem fileSystem; synchronized (fileSystems) { - if ((fileSystem = fileSystems.get(id)) != null) { + if (fileSystems.containsKey(id)) { throw new FileSystemAlreadyExistsException(id); } // TODO try and find a way to avoid doing this while locking the file systems cache - ClientSession session=null; + ClientSession session = null; try { session = client.connect(username, host, port) - .verify(FactoryManagerUtils.getLongProperty(env, CONNECT_TIME_PROP_NAME, DEFAULT_CONNECT_TIME)) - .getSession() - ; + .verify(FactoryManagerUtils.getLongProperty(env, CONNECT_TIME_PROP_NAME, DEFAULT_CONNECT_TIME)) + .getSession(); session.addPasswordIdentity(password); session.auth().verify(FactoryManagerUtils.getLongProperty(env, AUTH_TIME_PROP_NAME, DEFAULT_AUTH_TIME)); fileSystem = new SftpFileSystem(this, id, session, getSftpVersionSelector()); fileSystems.put(id, fileSystem); - } catch(Exception e) { + } catch (Exception e) { if (session != null) { try { session.close(); - } catch(IOException t) { + } catch (IOException t) { if (log.isDebugEnabled()) { log.debug("Failed (" + t.getClass().getSimpleName() + ")" + " to close session for new file system on " + host + ":" + port @@ -186,7 +187,7 @@ public class SftpFileSystemProvider extends FileSystemProvider { } } } - + if (e instanceof IOException) { throw (IOException) e; } else if (e instanceof RuntimeException) { @@ -196,7 +197,7 @@ public class SftpFileSystemProvider extends FileSystemProvider { } } } - + fileSystem.setReadBufferSize(FactoryManagerUtils.getIntProperty(env, READ_BUFFER_PROP_NAME, DEFAULT_READ_BUFFER_SIZE)); fileSystem.setWriteBufferSize(FactoryManagerUtils.getIntProperty(env, WRITE_BUFFER_PROP_NAME, DEFAULT_WRITE_BUFFER_SIZE)); return fileSystem; @@ -206,14 +207,13 @@ public class SftpFileSystemProvider extends FileSystemProvider { String id = getFileSystemIdentifier(session); SftpFileSystem fileSystem; synchronized (fileSystems) { - if ((fileSystem=fileSystems.get(id)) != null) { + if (fileSystems.containsKey(id)) { throw new FileSystemAlreadyExistsException(id); } - fileSystem = new SftpFileSystem(this, id, session, getSftpVersionSelector()); fileSystems.put(id, fileSystem); } - + FactoryManager manager = session.getFactoryManager(); fileSystem.setReadBufferSize(FactoryManagerUtils.getIntProperty(manager, READ_BUFFER_PROP_NAME, DEFAULT_READ_BUFFER_SIZE)); fileSystem.setWriteBufferSize(FactoryManagerUtils.getIntProperty(manager, WRITE_BUFFER_PROP_NAME, DEFAULT_WRITE_BUFFER_SIZE)); @@ -309,63 +309,7 @@ public class SftpFileSystemProvider extends FileSystemProvider { @Override public DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter) throws IOException { final SftpPath p = toSftpPath(dir); - return new DirectoryStream<Path>() { - private final SftpFileSystem fs = p.getFileSystem(); - private final SftpClient sftp = fs.getClient(); - private final Iterable<SftpClient.DirEntry> iter = sftp.readDir(p.toString()); - - @Override - public Iterator<Path> iterator() { - return new Iterator<Path>() { - @SuppressWarnings("synthetic-access") - private final Iterator<SftpClient.DirEntry> it = (iter == null) ? null : iter.iterator(); - private boolean dotIgnored, dotdotIgnored; - private SftpClient.DirEntry curEntry = nextEntry(); - - @Override - public boolean hasNext() { - return (curEntry != null); - } - - @Override - public Path next() { - if (curEntry == null) { - throw new NoSuchElementException("No next entry"); - } - - SftpClient.DirEntry entry = curEntry; - curEntry = nextEntry(); - return p.resolve(entry.filename); - } - - private SftpClient.DirEntry nextEntry() { - while((it != null) && it.hasNext()) { - SftpClient.DirEntry entry = it.next(); - String name = entry.filename; - if (".".equals(name) && (!dotIgnored)) { - dotIgnored = true; - } else if ("..".equals(name) && (!dotdotIgnored)) { - dotdotIgnored = true; - } else { - return entry; - } - } - - return null; - } - - @Override - public void remove() { - throw new UnsupportedOperationException("newDirectoryStream(" + p + ") Iterator#remove() N/A"); - } - }; - } - - @Override - public void close() throws IOException { - sftp.close(); - } - }; + return new PathDirectoryStream(p); } @Override @@ -376,7 +320,7 @@ public class SftpFileSystemProvider extends FileSystemProvider { try { sftp.mkdir(dir.toString()); } catch (SftpException e) { - int sftpStatus=e.getStatus(); + int sftpStatus = e.getStatus(); if ((sftp.getVersion() == SftpConstants.SFTP_V3) && (sftpStatus == SftpConstants.SSH_FX_FAILURE)) { try { Attributes attributes = sftp.stat(dir.toString()); @@ -402,7 +346,7 @@ public class SftpFileSystemProvider extends FileSystemProvider { public void delete(Path path) throws IOException { SftpPath p = toSftpPath(path); checkAccess(p, AccessMode.WRITE); - + SftpFileSystem fs = p.getFileSystem(); try (SftpClient sftp = fs.getClient()) { BasicFileAttributes attributes = readAttributes(path, BasicFileAttributes.class); @@ -435,11 +379,12 @@ public class SftpFileSystemProvider extends FileSystemProvider { // attributes of source file BasicFileAttributes attrs = readAttributes(source, BasicFileAttributes.class, linkOptions); - if (attrs.isSymbolicLink()) + if (attrs.isSymbolicLink()) { throw new IOException("Copying of symbolic links not supported"); + } // delete target if it exists and REPLACE_EXISTING is specified - Boolean status=IoUtils.checkFileExists(target, linkOptions); + Boolean status = IoUtils.checkFileExists(target, linkOptions); if (status == null) { throw new AccessDeniedException("Existence cannot be determined for copy target: " + target); } @@ -482,9 +427,9 @@ public class SftpFileSystemProvider extends FileSystemProvider { @Override public void move(Path source, Path target, CopyOption... options) throws IOException { SftpPath src = toSftpPath(source); - SftpFileSystem fsSrc = src.getFileSystem(); + SftpFileSystem fsSrc = src.getFileSystem(); SftpPath dst = toSftpPath(target); - + if (src.getFileSystem() != dst.getFileSystem()) { throw new ProviderMismatchException("Mismatched file system providers for " + src + " vs. " + dst); } @@ -507,7 +452,7 @@ public class SftpFileSystemProvider extends FileSystemProvider { } // delete target if it exists and REPLACE_EXISTING is specified - Boolean status=IoUtils.checkFileExists(target, linkOptions); + Boolean status = IoUtils.checkFileExists(target, linkOptions); if (status == null) { throw new AccessDeniedException("Existence cannot be determined for move target " + target); } @@ -562,14 +507,14 @@ public class SftpFileSystemProvider extends FileSystemProvider { if (!(fs instanceof SftpFileSystem)) { throw new FileSystemException(path.toString(), path.toString(), "getFileStore(" + path + ") path not attached to an SFTP file system"); } - + SftpFileSystem sftpFs = (SftpFileSystem) fs; String id = sftpFs.getId(); SftpFileSystem cached = getFileSystem(id); if (cached != sftpFs) { throw new FileSystemException(path.toString(), path.toString(), "Mismatched file system instance for id=" + id); } - + return sftpFs.getFileStores().get(0); } @@ -621,7 +566,7 @@ public class SftpFileSystemProvider extends FileSystemProvider { if ((attrs == null) && !(p.isAbsolute() && p.getNameCount() == 0)) { throw new NoSuchFileException(path.toString()); } - + SftpFileSystem fs = p.getFileSystem(); if (x || (w && fs.isReadOnly())) { throw new AccessDeniedException("Filesystem is read-only: " + path.toString()); @@ -631,140 +576,14 @@ public class SftpFileSystemProvider extends FileSystemProvider { @Override public <V extends FileAttributeView> V getFileAttributeView(final Path path, Class<V> type, final LinkOption... options) { if (isSupportedFileAttributeView(type)) { - return type.cast(new PosixFileAttributeView() { - @Override - public String name() { - return "view"; - } - - @SuppressWarnings("synthetic-access") - @Override - public PosixFileAttributes readAttributes() throws IOException { - SftpPath p = toSftpPath(path); - SftpFileSystem fs = p.getFileSystem(); - final SftpClient.Attributes attributes; - try (SftpClient client =fs.getClient()) { - try { - if (IoUtils.followLinks(options)) { - attributes = client.stat(p.toString()); - } else { - attributes = client.lstat(p.toString()); - } - } catch (SftpException e) { - if (e.getStatus() == SftpConstants.SSH_FX_NO_SUCH_FILE) { - throw new NoSuchFileException(p.toString()); - } - throw e; - } - } - return new PosixFileAttributes() { - @Override - public UserPrincipal owner() { - return attributes.owner != null ? new SftpFileSystem.DefaultGroupPrincipal(attributes.owner) : null; - } - - @Override - public GroupPrincipal group() { - return attributes.group != null ? new SftpFileSystem.DefaultGroupPrincipal(attributes.group) : null; - } - - @Override - public Set<PosixFilePermission> permissions() { - return permissionsToAttributes(attributes.perms); - } - - @Override - public FileTime lastModifiedTime() { - return FileTime.from(attributes.mtime, TimeUnit.SECONDS); - } - - @Override - public FileTime lastAccessTime() { - return FileTime.from(attributes.atime, TimeUnit.SECONDS); - } - - @Override - public FileTime creationTime() { - return FileTime.from(attributes.ctime, TimeUnit.SECONDS); - } - - @Override - public boolean isRegularFile() { - return attributes.isRegularFile(); - } - - @Override - public boolean isDirectory() { - return attributes.isDirectory(); - } - - @Override - public boolean isSymbolicLink() { - return attributes.isSymbolicLink(); - } - - @Override - public boolean isOther() { - return attributes.isOther(); - } - - @Override - public long size() { - return attributes.size; - } - - @Override - public Object fileKey() { - // TODO - return null; - } - }; - } - - @Override - public void setTimes(FileTime lastModifiedTime, FileTime lastAccessTime, FileTime createTime) throws IOException { - if (lastModifiedTime != null) { - setAttribute(path, "lastModifiedTime", lastModifiedTime, options); - } - if (lastAccessTime != null) { - setAttribute(path, "lastAccessTime", lastAccessTime, options); - } - if (createTime != null) { - setAttribute(path, "createTime", createTime, options); - } - } - - @Override - public void setPermissions(Set<PosixFilePermission> perms) throws IOException { - setAttribute(path, "permissions", perms, options); - } - - @Override - public void setGroup(GroupPrincipal group) throws IOException { - setAttribute(path, "group", group, options); - } - - @Override - public UserPrincipal getOwner() throws IOException { - return readAttributes().owner(); - } - - @Override - public void setOwner(UserPrincipal owner) throws IOException { - setAttribute(path, "owner", owner, options); - } - }); + return type.cast(new SftpPosixFileAttributeView(path, options)); } else { throw new UnsupportedOperationException("getFileAttributeView(" + path + ") view not supported: " + type.getSimpleName()); } } public boolean isSupportedFileAttributeView(Class<? extends FileAttributeView> type) { - if ((type != null) && SUPPORTED_VIEWS.contains(type)) { - return true; - } else { - return false; // debug breakpoint - } + return (type != null) && SUPPORTED_VIEWS.contains(type); } @Override @@ -880,11 +699,10 @@ public class SftpFileSystemProvider extends FileSystemProvider { case "size": attributes.size(((Number) value).longValue()); break; - case "permissions": { + case "permissions": @SuppressWarnings("unchecked") - Set<PosixFilePermission> attrSet = (Set<PosixFilePermission>) value; + Set<PosixFilePermission> attrSet = (Set<PosixFilePermission>) value; attributes.perms(attributesToPermissions(path, attrSet)); - } break; case "owner": attributes.owner(((UserPrincipal) value).getName()); @@ -898,7 +716,7 @@ public class SftpFileSystemProvider extends FileSystemProvider { case "isOther": case "fileKey": throw new UnsupportedOperationException("setAttribute(" + path + ")[" + attribute + "=" + value + "]" - + " unknown view=" + view + " attribute: " + attr); + + " unknown view=" + view + " attribute: " + attr); default: if (log.isTraceEnabled()) { log.trace("setAttribute({})[{}] ignore {}={}", path, attribute, attr, value); @@ -964,7 +782,7 @@ public class SftpFileSystemProvider extends FileSystemProvider { } public static String getRWXPermissions(int perms) { - StringBuilder sb=new StringBuilder(10 /* 3 * rwx + (d)irectory */); + StringBuilder sb = new StringBuilder(10 /* 3 * rwx + (d)irectory */); if ((perms & SftpConstants.S_IFLNK) == SftpConstants.S_IFLNK) { sb.append('l'); } else if ((perms & SftpConstants.S_IFDIR) == SftpConstants.S_IFDIR) { @@ -1020,7 +838,7 @@ public class SftpFileSystemProvider extends FileSystemProvider { } else { sb.append('-'); } - + return sb.toString(); } @@ -1101,8 +919,9 @@ public class SftpFileSystemProvider extends FileSystemProvider { /** * Uses the host, port and username to create a unique identifier + * * @param uri The {@link URI} - <B>Note:</B> not checked to make sure - * that the scheme is {@code sftp://} + * that the scheme is {@code sftp://} * @return The unique identifier * @see #getFileSystemIdentifier(String, int, String) */ @@ -1112,9 +931,10 @@ public class SftpFileSystemProvider extends FileSystemProvider { ValidateUtils.checkTrue(GenericUtils.length(ui) == 2, "Invalid user info: %s", userInfo); return getFileSystemIdentifier(uri.getHost(), uri.getPort(), ui[0]); } - + /** * Uses the remote host address, port and current username to create a unique identifier + * * @param session The {@link ClientSession} * @return The unique identifier * @see #getFileSystemIdentifier(String, int, String) @@ -1140,4 +960,213 @@ public class SftpFileSystemProvider extends FileSystemProvider { public static URI createFileSystemURI(String host, int port, String username, String password) { return URI.create(SftpConstants.SFTP_SUBSYSTEM_NAME + "://" + username + ":" + password + "@" + host + ":" + port + "/"); } + + private static class PathDirectoryStream implements DirectoryStream<Path> { + private final SftpFileSystem fs; + private final SftpClient sftp; + private final Iterable<SftpClient.DirEntry> iter; + private final SftpPath p; + + public PathDirectoryStream(SftpPath p) throws IOException { + this.p = p; + fs = p.getFileSystem(); + sftp = fs.getClient(); + iter = sftp.readDir(p.toString()); + } + + @Override + public Iterator<Path> iterator() { + return new PathIterator(); + } + + @Override + public void close() throws IOException { + sftp.close(); + } + + private class PathIterator implements Iterator<Path> { + @SuppressWarnings("synthetic-access") + private final Iterator<SftpClient.DirEntry> it = (iter == null) ? null : iter.iterator(); + private boolean dotIgnored; + private boolean dotdotIgnored; + private SftpClient.DirEntry curEntry = nextEntry(); + + @Override + public boolean hasNext() { + return curEntry != null; + } + + @Override + public Path next() { + if (curEntry == null) { + throw new NoSuchElementException("No next entry"); + } + + SftpClient.DirEntry entry = curEntry; + curEntry = nextEntry(); + return p.resolve(entry.filename); + } + + private SftpClient.DirEntry nextEntry() { + while ((it != null) && it.hasNext()) { + SftpClient.DirEntry entry = it.next(); + String name = entry.filename; + if (".".equals(name) && (!dotIgnored)) { + dotIgnored = true; + } else if ("..".equals(name) && (!dotdotIgnored)) { + dotdotIgnored = true; + } else { + return entry; + } + } + + return null; + } + + @Override + public void remove() { + throw new UnsupportedOperationException("newDirectoryStream(" + p + ") Iterator#remove() N/A"); + } + } + } + + private class SftpPosixFileAttributeView implements PosixFileAttributeView { + private final Path path; + private final LinkOption[] options; + + public SftpPosixFileAttributeView(Path path, LinkOption... options) { + this.path = path; + this.options = options; + } + + @Override + public String name() { + return "view"; + } + + @SuppressWarnings("synthetic-access") + @Override + public PosixFileAttributes readAttributes() throws IOException { + SftpPath p = toSftpPath(path); + SftpFileSystem fs = p.getFileSystem(); + final Attributes attributes; + try (SftpClient client = fs.getClient()) { + try { + if (IoUtils.followLinks(options)) { + attributes = client.stat(p.toString()); + } else { + attributes = client.lstat(p.toString()); + } + } catch (SftpException e) { + if (e.getStatus() == SftpConstants.SSH_FX_NO_SUCH_FILE) { + throw new NoSuchFileException(p.toString()); + } + throw e; + } + } + return new SftpPosixFileAttributes(attributes); + } + + @Override + public void setTimes(FileTime lastModifiedTime, FileTime lastAccessTime, FileTime createTime) throws IOException { + if (lastModifiedTime != null) { + setAttribute(path, "lastModifiedTime", lastModifiedTime, options); + } + if (lastAccessTime != null) { + setAttribute(path, "lastAccessTime", lastAccessTime, options); + } + if (createTime != null) { + setAttribute(path, "createTime", createTime, options); + } + } + + @Override + public void setPermissions(Set<PosixFilePermission> perms) throws IOException { + setAttribute(path, "permissions", perms, options); + } + + @Override + public void setGroup(GroupPrincipal group) throws IOException { + setAttribute(path, "group", group, options); + } + + @Override + public UserPrincipal getOwner() throws IOException { + return readAttributes().owner(); + } + + @Override + public void setOwner(UserPrincipal owner) throws IOException { + setAttribute(path, "owner", owner, options); + } + + private class SftpPosixFileAttributes implements PosixFileAttributes { + private final Attributes attributes; + + public SftpPosixFileAttributes(Attributes attributes) { + this.attributes = attributes; + } + + @Override + public UserPrincipal owner() { + return attributes.owner != null ? new SftpFileSystem.DefaultGroupPrincipal(attributes.owner) : null; + } + + @Override + public GroupPrincipal group() { + return attributes.group != null ? new SftpFileSystem.DefaultGroupPrincipal(attributes.group) : null; + } + + @Override + public Set<PosixFilePermission> permissions() { + return permissionsToAttributes(attributes.perms); + } + + @Override + public FileTime lastModifiedTime() { + return FileTime.from(attributes.mtime, TimeUnit.SECONDS); + } + + @Override + public FileTime lastAccessTime() { + return FileTime.from(attributes.atime, TimeUnit.SECONDS); + } + + @Override + public FileTime creationTime() { + return FileTime.from(attributes.ctime, TimeUnit.SECONDS); + } + + @Override + public boolean isRegularFile() { + return attributes.isRegularFile(); + } + + @Override + public boolean isDirectory() { + return attributes.isDirectory(); + } + + @Override + public boolean isSymbolicLink() { + return attributes.isSymbolicLink(); + } + + @Override + public boolean isOther() { + return attributes.isOther(); + } + + @Override + public long size() { + return attributes.size; + } + + @Override + public Object fileKey() { + // TODO + return null; + } + } + } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpVersionSelector.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpVersionSelector.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpVersionSelector.java index 40d9ad7..37d2094 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpVersionSelector.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpVersionSelector.java @@ -25,21 +25,23 @@ import java.util.List; * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> */ public interface SftpVersionSelector { + + /** + * An {@link SftpVersionSelector} that returns the current version + */ + SftpVersionSelector CURRENT = new SftpVersionSelector() { + @Override + public int selectVersion(int current, List<Integer> available) { + return current; + } + }; + /** - * @param current The current version negotiated with the server + * @param current The current version negotiated with the server * @param available Extra versions available - may be empty and/or contain - * only the current one + * only the current one * @return The new requested version - if same as current, then nothing is done */ int selectVersion(int current, List<Integer> available); - - /** - * An {@link SftpVersionSelector} that returns the current version - */ - SftpVersionSelector CURRENT = new SftpVersionSelector() { - @Override - public int selectVersion(int current, List<Integer> available) { - return current; - } - }; + } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/BuiltinSftpClientExtensions.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/BuiltinSftpClientExtensions.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/BuiltinSftpClientExtensions.java index 21da24c..cc2c223 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/BuiltinSftpClientExtensions.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/BuiltinSftpClientExtensions.java @@ -50,102 +50,103 @@ import org.apache.sshd.common.subsystem.sftp.extensions.openssh.StatVfsExtension * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> */ public enum BuiltinSftpClientExtensions implements SftpClientExtensionFactory { - COPY_FILE(SftpConstants.EXT_COPYFILE, CopyFileExtension.class) { - @Override // co-variant return - public CopyFileExtension create(SftpClient client, RawSftpClient raw, Map<String,byte[]> extensions, Map<String,?> parsed) { - return new CopyFileExtensionImpl(client, raw, ParserUtils.supportedExtensions(parsed)); - } - }, - COPY_DATA(SftpConstants.EXT_COPYDATA, CopyDataExtension.class) { - @Override // co-variant return - public CopyDataExtension create(SftpClient client, RawSftpClient raw, Map<String,byte[]> extensions, Map<String,?> parsed) { - return new CopyDataExtensionImpl(client, raw, ParserUtils.supportedExtensions(parsed)); - } - }, - MD5_FILE(SftpConstants.EXT_MD5HASH, MD5FileExtension.class) { - @Override // co-variant return - public MD5FileExtension create(SftpClient client, RawSftpClient raw, Map<String,byte[]> extensions, Map<String,?> parsed) { - return new MD5FileExtensionImpl(client, raw, ParserUtils.supportedExtensions(parsed)); - } - }, - MD5_HANDLE(SftpConstants.EXT_MD5HASH_HANDLE, MD5HandleExtension.class) { - @Override // co-variant return - public MD5HandleExtension create(SftpClient client, RawSftpClient raw, Map<String,byte[]> extensions, Map<String,?> parsed) { - return new MD5HandleExtensionImpl(client, raw, ParserUtils.supportedExtensions(parsed)); - } - }, - CHECK_FILE_NAME(SftpConstants.EXT_CHKFILE_NAME, CheckFileNameExtension.class) { - @Override // co-variant return - public CheckFileNameExtension create(SftpClient client, RawSftpClient raw, Map<String,byte[]> extensions, Map<String,?> parsed) { - return new CheckFileNameExtensionImpl(client, raw, ParserUtils.supportedExtensions(parsed)); - } - }, - CHECK_FILE_HANDLE(SftpConstants.EXT_CHKFILE_HANDLE, CheckFileHandleExtension.class) { - @Override // co-variant return - public CheckFileHandleExtension create(SftpClient client, RawSftpClient raw, Map<String,byte[]> extensions, Map<String,?> parsed) { - return new CheckFileHandleExtensionImpl(client, raw, ParserUtils.supportedExtensions(parsed)); - } - }, + COPY_FILE(SftpConstants.EXT_COPY_FILE, CopyFileExtension.class) { + @Override // co-variant return + public CopyFileExtension create(SftpClient client, RawSftpClient raw, Map<String, byte[]> extensions, Map<String, ?> parsed) { + return new CopyFileExtensionImpl(client, raw, ParserUtils.supportedExtensions(parsed)); + } + }, + COPY_DATA(SftpConstants.EXT_COPY_DATA, CopyDataExtension.class) { + @Override // co-variant return + public CopyDataExtension create(SftpClient client, RawSftpClient raw, Map<String, byte[]> extensions, Map<String, ?> parsed) { + return new CopyDataExtensionImpl(client, raw, ParserUtils.supportedExtensions(parsed)); + } + }, + MD5_FILE(SftpConstants.EXT_MD5_HASH, MD5FileExtension.class) { + @Override // co-variant return + public MD5FileExtension create(SftpClient client, RawSftpClient raw, Map<String, byte[]> extensions, Map<String, ?> parsed) { + return new MD5FileExtensionImpl(client, raw, ParserUtils.supportedExtensions(parsed)); + } + }, + MD5_HANDLE(SftpConstants.EXT_MD5_HASH_HANDLE, MD5HandleExtension.class) { + @Override // co-variant return + public MD5HandleExtension create(SftpClient client, RawSftpClient raw, Map<String, byte[]> extensions, Map<String, ?> parsed) { + return new MD5HandleExtensionImpl(client, raw, ParserUtils.supportedExtensions(parsed)); + } + }, + CHECK_FILE_NAME(SftpConstants.EXT_CHECK_FILE_NAME, CheckFileNameExtension.class) { + @Override // co-variant return + public CheckFileNameExtension create(SftpClient client, RawSftpClient raw, Map<String, byte[]> extensions, Map<String, ?> parsed) { + return new CheckFileNameExtensionImpl(client, raw, ParserUtils.supportedExtensions(parsed)); + } + }, + CHECK_FILE_HANDLE(SftpConstants.EXT_CHECK_FILE_HANDLE, CheckFileHandleExtension.class) { + @Override // co-variant return + public CheckFileHandleExtension create(SftpClient client, RawSftpClient raw, Map<String, byte[]> extensions, Map<String, ?> parsed) { + return new CheckFileHandleExtensionImpl(client, raw, ParserUtils.supportedExtensions(parsed)); + } + }, SPACE_AVAILABLE(SftpConstants.EXT_SPACE_AVAILABLE, SpaceAvailableExtension.class) { - @Override // co-variant return - public SpaceAvailableExtension create(SftpClient client, RawSftpClient raw, Map<String,byte[]> extensions, Map<String,?> parsed) { - return new SpaceAvailableExtensionImpl(client, raw, ParserUtils.supportedExtensions(parsed)); - } - }, + @Override // co-variant return + public SpaceAvailableExtension create(SftpClient client, RawSftpClient raw, Map<String, byte[]> extensions, Map<String, ?> parsed) { + return new SpaceAvailableExtensionImpl(client, raw, ParserUtils.supportedExtensions(parsed)); + } + }, OPENSSH_FSYNC(FsyncExtensionParser.NAME, OpenSSHFsyncExtension.class) { - @Override // co-variant return - public OpenSSHFsyncExtension create(SftpClient client, RawSftpClient raw, Map<String,byte[]> extensions, Map<String,?> parsed) { - return new OpenSSHFsyncExtensionImpl(client, raw, extensions); - } - }, + @Override // co-variant return + public OpenSSHFsyncExtension create(SftpClient client, RawSftpClient raw, Map<String, byte[]> extensions, Map<String, ?> parsed) { + return new OpenSSHFsyncExtensionImpl(client, raw, extensions); + } + }, OPENSSH_STAT_HANDLE(FstatVfsExtensionParser.NAME, OpenSSHStatHandleExtension.class) { - @Override // co-variant return - public OpenSSHStatHandleExtension create(SftpClient client, RawSftpClient raw, Map<String,byte[]> extensions, Map<String,?> parsed) { - return new OpenSSHStatHandleExtensionImpl(client, raw, extensions); - } - }, + @Override // co-variant return + public OpenSSHStatHandleExtension create(SftpClient client, RawSftpClient raw, Map<String, byte[]> extensions, Map<String, ?> parsed) { + return new OpenSSHStatHandleExtensionImpl(client, raw, extensions); + } + }, OPENSSH_STAT_PATH(StatVfsExtensionParser.NAME, OpenSSHStatPathExtension.class) { - @Override // co-variant return - public OpenSSHStatPathExtension create(SftpClient client, RawSftpClient raw, Map<String,byte[]> extensions, Map<String,?> parsed) { - return new OpenSSHStatPathExtensionImpl(client, raw, extensions); - } - }; + @Override // co-variant return + public OpenSSHStatPathExtension create(SftpClient client, RawSftpClient raw, Map<String, byte[]> extensions, Map<String, ?> parsed) { + return new OpenSSHStatPathExtensionImpl(client, raw, extensions); + } + }; + + public static final Set<BuiltinSftpClientExtensions> VALUES = + Collections.unmodifiableSet(EnumSet.allOf(BuiltinSftpClientExtensions.class)); private final String name; + private final Class<? extends SftpClientExtension> type; + + BuiltinSftpClientExtensions(String name, Class<? extends SftpClientExtension> type) { + this.name = name; + this.type = type; + } + @Override public final String getName() { return name; } - private final Class<? extends SftpClientExtension> type; public final Class<? extends SftpClientExtension> getType() { return type; } - private BuiltinSftpClientExtensions(String name, Class<? extends SftpClientExtension> type) { - this.name = name; - this.type = type; - } - @Override public SftpClientExtension create(SftpClient client, RawSftpClient raw) { - Map<String,byte[]> extensions = client.getServerExtensions(); + Map<String, byte[]> extensions = client.getServerExtensions(); return create(client, raw, extensions, ParserUtils.parse(extensions)); } - public static final Set<BuiltinSftpClientExtensions> VALUES = - Collections.unmodifiableSet(EnumSet.allOf(BuiltinSftpClientExtensions.class)); - - public static final BuiltinSftpClientExtensions fromName(String n) { + public static BuiltinSftpClientExtensions fromName(String n) { return NamedResource.Utils.findByName(n, String.CASE_INSENSITIVE_ORDER, VALUES); } - - public static final BuiltinSftpClientExtensions fromInstance(Object o) { + + public static BuiltinSftpClientExtensions fromInstance(Object o) { return fromType((o == null) ? null : o.getClass()); } - public static final BuiltinSftpClientExtensions fromType(Class<?> type) { + public static BuiltinSftpClientExtensions fromType(Class<?> type) { if ((type == null) || (!SftpClientExtension.class.isAssignableFrom(type))) { return null; } @@ -161,7 +162,7 @@ public enum BuiltinSftpClientExtensions implements SftpClientExtensionFactory { return v; } } - + return null; } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/CheckFileHandleExtension.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/CheckFileHandleExtension.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/CheckFileHandleExtension.java index 40bdd4c..f192d51 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/CheckFileHandleExtension.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/CheckFileHandleExtension.java @@ -31,16 +31,16 @@ import org.apache.sshd.common.util.Pair; */ public interface CheckFileHandleExtension extends SftpClientExtension { /** - * @param handle Remote file {@link Handle} - must be a file and opened for read - * @param algorithms Hash algorithms in preferred order + * @param handle Remote file {@link Handle} - must be a file and opened for read + * @param algorithms Hash algorithms in preferred order * @param startOffset Start offset of the hash - * @param length Length of data to hash - if zero then till EOF - * @param blockSize Input block size to calculate individual hashes - if - * zero the <U>one</U> hash of <U>all</U> the data + * @param length Length of data to hash - if zero then till EOF + * @param blockSize Input block size to calculate individual hashes - if + * zero the <U>one</U> hash of <U>all</U> the data * @return A {@link Pair} where left=hash algorithm name, right=the calculated * hashes. * @throws IOException If failed to execute the command */ - Pair<String,Collection<byte[]>> checkFileHandle(Handle handle, Collection<String> algorithms, long startOffset, long length, int blockSize) throws IOException; + Pair<String, Collection<byte[]>> checkFileHandle(Handle handle, Collection<String> algorithms, long startOffset, long length, int blockSize) throws IOException; } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/CheckFileNameExtension.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/CheckFileNameExtension.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/CheckFileNameExtension.java index cb908f4..2735d20 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/CheckFileNameExtension.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/CheckFileNameExtension.java @@ -30,15 +30,15 @@ import org.apache.sshd.common.util.Pair; */ public interface CheckFileNameExtension extends SftpClientExtension { /** - * @param name Remote file name/path - * @param algorithms Hash algorithms in preferred order + * @param name Remote file name/path + * @param algorithms Hash algorithms in preferred order * @param startOffset Start offset of the hash - * @param length Length of data to hash - if zero then till EOF - * @param blockSize Input block size to calculate individual hashes - if - * zero the <U>one</U> hash of <U>all</U> the data + * @param length Length of data to hash - if zero then till EOF + * @param blockSize Input block size to calculate individual hashes - if + * zero the <U>one</U> hash of <U>all</U> the data * @return A {@link Pair} where left=hash algorithm name, right=the calculated * hashes. * @throws IOException If failed to execute the command */ - Pair<String,Collection<byte[]>> checkFileName(String name, Collection<String> algorithms, long startOffset, long length, int blockSize) throws IOException; + Pair<String, Collection<byte[]>> checkFileName(String name, Collection<String> algorithms, long startOffset, long length, int blockSize) throws IOException; } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/CopyDataExtension.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/CopyDataExtension.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/CopyDataExtension.java index 64025bc..9033a3f 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/CopyDataExtension.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/CopyDataExtension.java @@ -25,6 +25,7 @@ import org.apache.sshd.client.subsystem.sftp.SftpClient.Handle; /** * Implements the "copy-data" extension + * * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> * @see <A HREF="http://tools.ietf.org/id/draft-ietf-secsh-filexfer-extensions-00.txt">DRAFT 00 section 7</A> */ http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/CopyFileExtension.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/CopyFileExtension.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/CopyFileExtension.java index b78228f..33b7225 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/CopyFileExtension.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/CopyFileExtension.java @@ -27,8 +27,8 @@ import java.io.IOException; */ public interface CopyFileExtension extends SftpClientExtension { /** - * @param src The (<U>remote</U>) file source path - * @param dst The (<U>remote</U>) file destination path + * @param src The (<U>remote</U>) file source path + * @param dst The (<U>remote</U>) file destination path * @param overwriteDestination If {@code true} then OK to override destination if exists * @throws IOException If failed to execute the command or extension not supported */ http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/MD5FileExtension.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/MD5FileExtension.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/MD5FileExtension.java index 4706e76..f914f67 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/MD5FileExtension.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/MD5FileExtension.java @@ -27,10 +27,10 @@ import java.io.IOException; */ public interface MD5FileExtension extends SftpClientExtension { /** - * @param path The (remote) path - * @param offset The offset to start calculating the hash - * @param length The number of data bytes to calculate the hash on - if - * greater than available, then up to whatever is available + * @param path The (remote) path + * @param offset The offset to start calculating the hash + * @param length The number of data bytes to calculate the hash on - if + * greater than available, then up to whatever is available * @param quickHash A quick-hash of the 1st 2048 bytes - ignored if {@code null}/empty * @return The hash value if the quick hash matches (or {@code null}/empty), or * {@code null}/empty if the quick hash is provided and it does not match http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/MD5HandleExtension.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/MD5HandleExtension.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/MD5HandleExtension.java index 1188b50..f6a28db 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/MD5HandleExtension.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/MD5HandleExtension.java @@ -29,10 +29,10 @@ import org.apache.sshd.client.subsystem.sftp.SftpClient; */ public interface MD5HandleExtension extends SftpClientExtension { /** - * @param handle The (remote) file {@link SftpClient.Handle} - * @param offset The offset to start calculating the hash - * @param length The number of data bytes to calculate the hash on - if - * greater than available, then up to whatever is available + * @param handle The (remote) file {@link SftpClient.Handle} + * @param offset The offset to start calculating the hash + * @param length The number of data bytes to calculate the hash on - if + * greater than available, then up to whatever is available * @param quickHash A quick-hash of the 1st 2048 bytes - ignored if {@code null}/empty * @return The hash value if the quick hash matches (or {@code null}/empty), or * {@code null}/empty if the quick hash is provided and it does not match http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/SftpClientExtensionFactory.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/SftpClientExtensionFactory.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/SftpClientExtensionFactory.java index 3d07aa0..2ce2030 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/SftpClientExtensionFactory.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/SftpClientExtensionFactory.java @@ -31,5 +31,6 @@ import org.apache.sshd.common.NamedResource; public interface SftpClientExtensionFactory extends NamedResource { // TODO make this a default method for JDK-8 SftpClientExtension create(SftpClient client, RawSftpClient raw); - SftpClientExtension create(SftpClient client, RawSftpClient raw, Map<String,byte[]> extensions, Map<String,?> parsed); + + SftpClientExtension create(SftpClient client, RawSftpClient raw, Map<String, byte[]> extensions, Map<String, ?> parsed); } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/SpaceAvailableExtension.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/SpaceAvailableExtension.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/SpaceAvailableExtension.java index bec900e..5f0df59 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/SpaceAvailableExtension.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/SpaceAvailableExtension.java @@ -25,8 +25,9 @@ import org.apache.sshd.common.subsystem.sftp.extensions.SpaceAvailableExtensionI /** * Implements the "space-availble" extension + * * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> - * @see <A HREF="http://tools.ietf.org/wg/secsh/draft-ietf-secsh-filexfer/draft-ietf-secsh-filexfer-09.txt">DRAFT 09 section 9.2</A> + * @see <A HREF="http://tools.ietf.org/wg/secsh/draft-ietf-secsh-filexfer/draft-ietf-secsh-filexfer-09.txt">DRAFT 09 section 9.2</A> */ public interface SpaceAvailableExtension extends SftpClientExtension { SpaceAvailableExtensionInfo available(String path) throws IOException; http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/AbstractCheckFileExtension.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/AbstractCheckFileExtension.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/AbstractCheckFileExtension.java index fa4ca35..947dc2d 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/AbstractCheckFileExtension.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/AbstractCheckFileExtension.java @@ -40,28 +40,28 @@ public abstract class AbstractCheckFileExtension extends AbstractSftpClientExten super(name, client, raw, extras); } - protected Pair<String,Collection<byte[]>> doGetHash(Object target, Collection<String> algorithms, long offset, long length, int blockSize) throws IOException { + protected Pair<String, Collection<byte[]>> doGetHash(Object target, Collection<String> algorithms, long offset, long length, int blockSize) throws IOException { Buffer buffer = getCommandBuffer(target, Byte.MAX_VALUE); putTarget(buffer, target); buffer.putString(GenericUtils.join(algorithms, ',')); buffer.putLong(offset); buffer.putLong(length); buffer.putInt(blockSize); - + if (log.isDebugEnabled()) { log.debug("doGetHash({})[{}] - offset={}, length={}, block-size={}", - getName(), (target instanceof CharSequence) ? target : BufferUtils.printHex(BufferUtils.EMPTY_HEX_SEPARATOR, (byte[]) target), - Long.valueOf(offset), Long.valueOf(length), Integer.valueOf(blockSize)); + getName(), (target instanceof CharSequence) ? target : BufferUtils.printHex(BufferUtils.EMPTY_HEX_SEPARATOR, (byte[]) target), + offset, length, blockSize); } buffer = checkExtendedReplyBuffer(receive(sendExtendedCommand(buffer))); if (buffer == null) { throw new StreamCorruptedException("Missing extended reply data"); } - + String targetType = buffer.getString(); - if (String.CASE_INSENSITIVE_ORDER.compare(targetType, SftpConstants.EXT_CHKFILE_RESPONSE) != 0) { - throw new StreamCorruptedException("Mismatched reply type: expected=" + SftpConstants.EXT_CHKFILE_RESPONSE + ", actual=" + targetType); + if (String.CASE_INSENSITIVE_ORDER.compare(targetType, SftpConstants.EXT_CHECK_FILE) != 0) { + throw new StreamCorruptedException("Mismatched reply type: expected=" + SftpConstants.EXT_CHECK_FILE + ", actual=" + targetType); } String algo = buffer.getString(); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/AbstractMD5HashExtension.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/AbstractMD5HashExtension.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/AbstractMD5HashExtension.java index 8c8a5d5..a63a7ac 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/AbstractMD5HashExtension.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/AbstractMD5HashExtension.java @@ -44,18 +44,18 @@ public abstract class AbstractMD5HashExtension extends AbstractSftpClientExtensi buffer.putLong(offset); buffer.putLong(length); buffer.putBytes((quickHash == null) ? GenericUtils.EMPTY_BYTE_ARRAY : quickHash); - + if (log.isDebugEnabled()) { log.debug("doGetHash({})[{}] - offset={}, length={}, quick-hash={}", - opcode, (target instanceof CharSequence) ? target : BufferUtils.printHex(BufferUtils.EMPTY_HEX_SEPARATOR, (byte[]) target), - Long.valueOf(offset), Long.valueOf(length), BufferUtils.printHex(':', quickHash)); + opcode, (target instanceof CharSequence) ? target : BufferUtils.printHex(BufferUtils.EMPTY_HEX_SEPARATOR, (byte[]) target), + offset, length, BufferUtils.printHex(':', quickHash)); } buffer = checkExtendedReplyBuffer(receive(sendExtendedCommand(buffer))); if (buffer == null) { throw new StreamCorruptedException("Missing extended reply data"); } - + String targetType = buffer.getString(); if (String.CASE_INSENSITIVE_ORDER.compare(targetType, opcode) != 0) { throw new StreamCorruptedException("Mismatched reply target type: expected=" + opcode + ", actual=" + targetType); @@ -64,10 +64,10 @@ public abstract class AbstractMD5HashExtension extends AbstractSftpClientExtensi byte[] hashValue = buffer.getBytes(); if (log.isDebugEnabled()) { log.debug("doGetHash({})[{}] - offset={}, length={}, quick-hash={} - result={}", - opcode, target, Long.valueOf(offset), Long.valueOf(length), + opcode, target, offset, length, BufferUtils.printHex(':', quickHash), BufferUtils.printHex(':', hashValue)); } - + return hashValue; } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/AbstractSftpClientExtension.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/AbstractSftpClientExtension.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/AbstractSftpClientExtension.java index 11b23f1..e9f2e0e 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/AbstractSftpClientExtension.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/AbstractSftpClientExtension.java @@ -26,8 +26,8 @@ import java.util.Map; import org.apache.sshd.client.subsystem.sftp.RawSftpClient; import org.apache.sshd.client.subsystem.sftp.SftpClient; -import org.apache.sshd.client.subsystem.sftp.SftpException; import org.apache.sshd.client.subsystem.sftp.SftpClient.Handle; +import org.apache.sshd.client.subsystem.sftp.SftpException; import org.apache.sshd.client.subsystem.sftp.extensions.SftpClientExtension; import org.apache.sshd.common.SshException; import org.apache.sshd.common.subsystem.sftp.SftpConstants; @@ -45,12 +45,12 @@ public abstract class AbstractSftpClientExtension extends AbstractLoggingBean im private final SftpClient client; private final RawSftpClient raw; private final boolean supported; - + protected AbstractSftpClientExtension(String name, SftpClient client, RawSftpClient raw, Collection<String> extras) { this(name, client, raw, GenericUtils.isEmpty(extras) ? false : extras.contains(name)); } - protected AbstractSftpClientExtension(String name, SftpClient client, RawSftpClient raw, Map<String,byte[]> extensions) { + protected AbstractSftpClientExtension(String name, SftpClient client, RawSftpClient raw, Map<String, byte[]> extensions) { this(name, client, raw, GenericUtils.isEmpty(extensions) ? false : extensions.containsKey(name)); } @@ -107,10 +107,10 @@ public abstract class AbstractSftpClientExtension extends AbstractLoggingBean im /** * @param buffer The {@link Buffer} * @param target A target path {@link String} or {@link Handle} or {@code byte[]) - * to be encoded in the buffer + * to be encoded in the buffer * @return The updated buffer * @throws UnsupportedOperationException If target is not one of the above - * supported types + * supported types */ public Buffer putTarget(Buffer buffer, Object target) { if (target instanceof CharSequence) { @@ -128,7 +128,7 @@ public abstract class AbstractSftpClientExtension extends AbstractLoggingBean im /** * @param target A target path {@link String} or {@link Handle} or {@code byte[]) - * to be encoded in the buffer + * to be encoded in the buffer * @return A {@link Buffer} with the extension name set * @see #getCommandBuffer(Object, int) */ @@ -137,8 +137,8 @@ public abstract class AbstractSftpClientExtension extends AbstractLoggingBean im } /** - * @param target A target path {@link String} or {@link Handle} or {@code byte[]) - * to be encoded in the buffer + * @param target A target path {@link String} or {@link Handle} or {@code byte[]) + * to be encoded in the buffer * @param extraSize Extra size - beyond the path/handle to be allocated * @return A {@link Buffer} with the extension name set * @see #getCommandBuffer(int) @@ -172,7 +172,7 @@ public abstract class AbstractSftpClientExtension extends AbstractLoggingBean im * or {@code null} if this is a {@link SftpConstants#SSH_FXP_STATUS} carrying * an {@link SftpConstants#SSH_FX_OK} result * @throws IOException If a non-{@link SftpConstants#SSH_FX_OK} result or - * not a {@link SftpConstants#SSH_FXP_EXTENDED_REPLY} buffer + * not a {@link SftpConstants#SSH_FXP_EXTENDED_REPLY} buffer */ protected Buffer checkExtendedReplyBuffer(Buffer buffer) throws IOException { int length = buffer.getInt(); @@ -184,13 +184,13 @@ public abstract class AbstractSftpClientExtension extends AbstractLoggingBean im String lang = buffer.getString(); if (log.isDebugEnabled()) { log.debug("checkStatus({}}[id={}] - status: {} [{}] {}", - getName(), Integer.valueOf(id), Integer.valueOf(substatus), lang, msg); + getName(), id, substatus, lang, msg); } if (substatus != SftpConstants.SSH_FX_OK) { throwStatusException(id, substatus, msg, lang); } - + return null; } else if (type == SftpConstants.SSH_FXP_EXTENDED_REPLY) { return buffer; http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CheckFileHandleExtensionImpl.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CheckFileHandleExtensionImpl.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CheckFileHandleExtensionImpl.java index fabc3f3..09cb30a 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CheckFileHandleExtensionImpl.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CheckFileHandleExtensionImpl.java @@ -34,7 +34,7 @@ import org.apache.sshd.common.util.Pair; */ public class CheckFileHandleExtensionImpl extends AbstractCheckFileExtension implements CheckFileHandleExtension { public CheckFileHandleExtensionImpl(SftpClient client, RawSftpClient raw, Collection<String> extras) { - super(SftpConstants.EXT_CHKFILE_HANDLE, client, raw, extras); + super(SftpConstants.EXT_CHECK_FILE_HANDLE, client, raw, extras); } @Override http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CheckFileNameExtensionImpl.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CheckFileNameExtensionImpl.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CheckFileNameExtensionImpl.java index b747cb0..4331db7 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CheckFileNameExtensionImpl.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CheckFileNameExtensionImpl.java @@ -33,7 +33,7 @@ import org.apache.sshd.common.util.Pair; */ public class CheckFileNameExtensionImpl extends AbstractCheckFileExtension implements CheckFileNameExtension { public CheckFileNameExtensionImpl(SftpClient client, RawSftpClient raw, Collection<String> extras) { - super(SftpConstants.EXT_CHKFILE_NAME, client, raw, extras); + super(SftpConstants.EXT_CHECK_FILE_NAME, client, raw, extras); } @Override http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CopyDataExtensionImpl.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CopyDataExtensionImpl.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CopyDataExtensionImpl.java index 318d813..32b2cd6 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CopyDataExtensionImpl.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CopyDataExtensionImpl.java @@ -35,15 +35,16 @@ import org.apache.sshd.common.util.buffer.Buffer; */ public class CopyDataExtensionImpl extends AbstractSftpClientExtension implements CopyDataExtension { public CopyDataExtensionImpl(SftpClient client, RawSftpClient raw, Collection<String> extra) { - super(SftpConstants.EXT_COPYDATA, client, raw, extra); + super(SftpConstants.EXT_COPY_DATA, client, raw, extra); } @Override public void copyData(Handle readHandle, long readOffset, long readLength, Handle writeHandle, long writeOffset) throws IOException { - byte[] srcId = readHandle.getIdentifier(), dstId = writeHandle.getIdentifier(); + byte[] srcId = readHandle.getIdentifier(); + byte[] dstId = writeHandle.getIdentifier(); Buffer buffer = getCommandBuffer((Integer.SIZE / Byte.SIZE) + GenericUtils.length(srcId) - + (Integer.SIZE / Byte.SIZE) + GenericUtils.length(dstId) - + (3 * (Long.SIZE + (Integer.SIZE / Byte.SIZE)))); + + (Integer.SIZE / Byte.SIZE) + GenericUtils.length(dstId) + + (3 * (Long.SIZE + (Integer.SIZE / Byte.SIZE)))); buffer.putBytes(srcId); buffer.putLong(readOffset); buffer.putLong(readLength); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CopyFileExtensionImpl.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CopyFileExtensionImpl.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CopyFileExtensionImpl.java index 28d7b18..b780fe5 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CopyFileExtensionImpl.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CopyFileExtensionImpl.java @@ -34,14 +34,14 @@ import org.apache.sshd.common.util.buffer.Buffer; */ public class CopyFileExtensionImpl extends AbstractSftpClientExtension implements CopyFileExtension { public CopyFileExtensionImpl(SftpClient client, RawSftpClient raw, Collection<String> extra) { - super(SftpConstants.EXT_COPYFILE, client, raw, extra); + super(SftpConstants.EXT_COPY_FILE, client, raw, extra); } @Override public void copyFile(String src, String dst, boolean overwriteDestination) throws IOException { Buffer buffer = getCommandBuffer((Integer.SIZE / Byte.SIZE) + GenericUtils.length(src) - + (Integer.SIZE / Byte.SIZE) + GenericUtils.length(dst) - + 1 /* override destination */); + + (Integer.SIZE / Byte.SIZE) + GenericUtils.length(dst) + + 1 /* override destination */); buffer.putString(src); buffer.putString(dst); buffer.putBoolean(overwriteDestination); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/MD5FileExtensionImpl.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/MD5FileExtensionImpl.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/MD5FileExtensionImpl.java index b0340be..84be6f1 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/MD5FileExtensionImpl.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/MD5FileExtensionImpl.java @@ -32,7 +32,7 @@ import org.apache.sshd.common.subsystem.sftp.SftpConstants; */ public class MD5FileExtensionImpl extends AbstractMD5HashExtension implements MD5FileExtension { public MD5FileExtensionImpl(SftpClient client, RawSftpClient raw, Collection<String> extra) { - super(SftpConstants.EXT_MD5HASH, client, raw, extra); + super(SftpConstants.EXT_MD5_HASH, client, raw, extra); } @Override http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/MD5HandleExtensionImpl.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/MD5HandleExtensionImpl.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/MD5HandleExtensionImpl.java index b5a482f..9e380e5 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/MD5HandleExtensionImpl.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/MD5HandleExtensionImpl.java @@ -32,7 +32,7 @@ import org.apache.sshd.common.subsystem.sftp.SftpConstants; */ public class MD5HandleExtensionImpl extends AbstractMD5HashExtension implements MD5HandleExtension { public MD5HandleExtensionImpl(SftpClient client, RawSftpClient raw, Collection<String> extra) { - super(SftpConstants.EXT_MD5HASH_HANDLE, client, raw, extra); + super(SftpConstants.EXT_MD5_HASH_HANDLE, client, raw, extra); } @Override http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/SpaceAvailableExtensionImpl.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/SpaceAvailableExtensionImpl.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/SpaceAvailableExtensionImpl.java index 17cc627..8077a0e 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/SpaceAvailableExtensionImpl.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/SpaceAvailableExtensionImpl.java @@ -47,7 +47,7 @@ public class SpaceAvailableExtensionImpl extends AbstractSftpClientExtension imp if (buffer == null) { throw new StreamCorruptedException("Missing extended reply data"); } - + return new SpaceAvailableExtensionInfo(buffer); } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/openssh/OpenSSHFsyncExtension.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/openssh/OpenSSHFsyncExtension.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/openssh/OpenSSHFsyncExtension.java index fdfc05b..0c11e5b 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/openssh/OpenSSHFsyncExtension.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/openssh/OpenSSHFsyncExtension.java @@ -26,6 +26,7 @@ import org.apache.sshd.client.subsystem.sftp.extensions.SftpClientExtension; /** * Implements the "[email protected]" extension + * * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> * @see <A HREF="https://github.com/openssh/openssh-portable/blob/master/PROTOCOL">OpenSSH</A> section 10 */ http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/openssh/OpenSSHStatExtensionInfo.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/openssh/OpenSSHStatExtensionInfo.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/openssh/OpenSSHStatExtensionInfo.java index 6213505..198ee67 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/openssh/OpenSSHStatExtensionInfo.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/openssh/OpenSSHStatExtensionInfo.java @@ -25,6 +25,7 @@ import org.apache.sshd.common.util.buffer.Buffer; /** * Response for the "[email protected]" and "[email protected]" * extension commands. + * * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> * @see <A HREF="http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/usr.bin/ssh/PROTOCOL?rev=1.28&content-type=text/plain">OpenSSH section 3.4</A> */ @@ -33,6 +34,7 @@ public class OpenSSHStatExtensionInfo implements Cloneable { public static final long SSH_FXE_STATVFS_ST_RDONLY = 0x1; /* read-only */ public static final long SSH_FXE_STATVFS_ST_NOSUID = 0x2; /* no setuid */ + // CHECKSTYLE:OFF public long f_bsize; /* file system block size */ public long f_frsize; /* fundamental fs block size */ public long f_blocks; /* number of blocks (unit f_frsize) */ @@ -44,7 +46,8 @@ public class OpenSSHStatExtensionInfo implements Cloneable { public long f_fsid; /* file system id */ public long f_flag; /* bit mask of f_flag values */ public long f_namemax; /* maximum filename length */ - + // CHECKSTYLE:ON + public OpenSSHStatExtensionInfo() { super(); } @@ -55,18 +58,18 @@ public class OpenSSHStatExtensionInfo implements Cloneable { @Override public int hashCode() { - return GenericUtils.hashCode(this.f_bsize) - + GenericUtils.hashCode(this.f_frsize) - + GenericUtils.hashCode(this.f_blocks) - + GenericUtils.hashCode(this.f_bfree) - + GenericUtils.hashCode(this.f_bavail) - + GenericUtils.hashCode(this.f_files) - + GenericUtils.hashCode(this.f_ffree) - + GenericUtils.hashCode(this.f_favail) - + GenericUtils.hashCode(this.f_fsid) - + GenericUtils.hashCode(this.f_flag) - + GenericUtils.hashCode(this.f_namemax) - ; + int result = GenericUtils.hashCode(this.f_bsize); + result = 31 * result + GenericUtils.hashCode(this.f_frsize); + result = 31 * result + GenericUtils.hashCode(this.f_blocks); + result = 31 * result + GenericUtils.hashCode(this.f_bfree); + result = 31 * result + GenericUtils.hashCode(this.f_bavail); + result = 31 * result + GenericUtils.hashCode(this.f_files); + result = 31 * result + GenericUtils.hashCode(this.f_ffree); + result = 31 * result + GenericUtils.hashCode(this.f_favail); + result = 31 * result + GenericUtils.hashCode(this.f_fsid); + result = 31 * result + GenericUtils.hashCode(this.f_flag); + result = 31 * result + GenericUtils.hashCode(this.f_namemax); + return result; } @Override @@ -82,28 +85,25 @@ public class OpenSSHStatExtensionInfo implements Cloneable { } OpenSSHStatExtensionInfo other = (OpenSSHStatExtensionInfo) obj; - if ((this.f_bsize == other.f_bsize) - && (this.f_frsize == other.f_frsize) - && (this.f_blocks == other.f_blocks) - && (this.f_bfree == other.f_bfree) - && (this.f_bavail == other.f_bavail) - && (this.f_files == other.f_files) - && (this.f_ffree == other.f_ffree) - && (this.f_favail == other.f_favail) - && (this.f_fsid == other.f_fsid) - && (this.f_flag == other.f_flag) - && (this.f_namemax == other.f_namemax)) { - return true; - } else { - return false; // debug breakpoint - } + // debug breakpoint + return this.f_bsize == other.f_bsize + && this.f_frsize == other.f_frsize + && this.f_blocks == other.f_blocks + && this.f_bfree == other.f_bfree + && this.f_bavail == other.f_bavail + && this.f_files == other.f_files + && this.f_ffree == other.f_ffree + && this.f_favail == other.f_favail + && this.f_fsid == other.f_fsid + && this.f_flag == other.f_flag + && this.f_namemax == other.f_namemax; } @Override public OpenSSHStatExtensionInfo clone() { try { return getClass().cast(super.clone()); - } catch(CloneNotSupportedException e) { + } catch (CloneNotSupportedException e) { throw new RuntimeException("Failed to close " + toString() + ": " + e.getMessage()); } } @@ -111,17 +111,16 @@ public class OpenSSHStatExtensionInfo implements Cloneable { @Override public String toString() { return "f_bsize=" + f_bsize - + ",f_frsize=" + f_frsize - + ",f_blocks=" + f_blocks - + ",f_bfree=" + f_bfree - + ",f_bavail=" + f_bavail - + ",f_files=" + f_files - + ",f_ffree=" + f_ffree - + ",f_favail=" + f_favail - + ",f_fsid=" + f_fsid - + ",f_flag=0x" + Long.toHexString(f_flag) - + ",f_namemax=" + f_namemax - ; + + ",f_frsize=" + f_frsize + + ",f_blocks=" + f_blocks + + ",f_bfree=" + f_bfree + + ",f_bavail=" + f_bavail + + ",f_files=" + f_files + + ",f_ffree=" + f_ffree + + ",f_favail=" + f_favail + + ",f_fsid=" + f_fsid + + ",f_flag=0x" + Long.toHexString(f_flag) + + ",f_namemax=" + f_namemax; } public static void encode(Buffer buffer, OpenSSHStatExtensionInfo info) { @@ -143,7 +142,7 @@ public class OpenSSHStatExtensionInfo implements Cloneable { decode(buffer, info); return info; } - + public static void decode(Buffer buffer, OpenSSHStatExtensionInfo info) { info.f_bsize = buffer.getLong(); info.f_frsize = buffer.getLong(); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/openssh/OpenSSHStatHandleExtension.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/openssh/OpenSSHStatHandleExtension.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/openssh/OpenSSHStatHandleExtension.java index e36067e..222b0a3 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/openssh/OpenSSHStatHandleExtension.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/openssh/OpenSSHStatHandleExtension.java @@ -26,6 +26,7 @@ import org.apache.sshd.client.subsystem.sftp.extensions.SftpClientExtension; /** * Implements the "[email protected]" extension command + * * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> */ public interface OpenSSHStatHandleExtension extends SftpClientExtension {
