This is an automated email from the ASF dual-hosted git repository. twolf pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mina-sshd.git
The following commit(s) were added to refs/heads/master by this push: new 06fe2de Clean-up: move longname calculation for chained SFTP file systems 06fe2de is described below commit 06fe2dee8630013750a0e8450b54ed23378417ee Author: Thomas Wolf <tw...@apache.org> AuthorDate: Thu Nov 18 23:47:22 2021 +0100 Clean-up: move longname calculation for chained SFTP file systems Move the newly introduced SftpHelper.getLongName() variant with SftpClient.Attributes as input to AbstractSftpSubsystemHelper, where it can be overridden if needed. It's also more in-line with the other getLongName() variants. --- .../org/apache/sshd/sftp/common/SftpHelper.java | 23 ---------------------- .../sftp/server/AbstractSftpSubsystemHelper.java | 15 +++++++++++++- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/sshd-sftp/src/main/java/org/apache/sshd/sftp/common/SftpHelper.java b/sshd-sftp/src/main/java/org/apache/sshd/sftp/common/SftpHelper.java index 4b5d245..4386df4 100644 --- a/sshd-sftp/src/main/java/org/apache/sshd/sftp/common/SftpHelper.java +++ b/sshd-sftp/src/main/java/org/apache/sshd/sftp/common/SftpHelper.java @@ -57,7 +57,6 @@ import org.apache.sshd.common.PropertyResolver; import org.apache.sshd.common.SshConstants; import org.apache.sshd.common.util.GenericUtils; import org.apache.sshd.common.util.MapEntryUtils; -import org.apache.sshd.common.util.MapEntryUtils.MapBuilder; import org.apache.sshd.common.util.OsUtils; import org.apache.sshd.common.util.ValidateUtils; import org.apache.sshd.common.util.buffer.Buffer; @@ -1202,28 +1201,6 @@ public final class SftpHelper { * <A HREF="https://tools.ietf.org/html/draft-ietf-secsh-filexfer-02">SFTP version 3 - section * 7</A> */ - public static String getLongName(String shortName, Attributes attributes) { - return getLongName(shortName, - MapBuilder.<String, Object> builder() - .put("owner", attributes.getOwner()) - .put("group", attributes.getGroup()) - .put("size", attributes.getSize()) - .put("isDirectory", attributes.isDirectory()) - .put("isSymbolicLink", attributes.isSymbolicLink()) - .put("permissions", permissionsToAttributes(attributes.getPermissions())) - .put("lastModifiedTime", attributes.getModifyTime()) - .build()); - } - - /** - * Creates an "ls -l" compatible long name string - * - * @param shortName The short file name - can also be "." or ".." - * @param attributes The file's attributes - e.g., size, owner, permissions, etc. - * @return A {@link String} representing the "long" file name as per - * <A HREF="https://tools.ietf.org/html/draft-ietf-secsh-filexfer-02">SFTP version 3 - section - * 7</A> - */ public static String getLongName(String shortName, Map<String, ?> attributes) { String owner = Objects.toString(attributes.get("owner"), null); String username = OsUtils.getCanonicalUser(owner); diff --git a/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/AbstractSftpSubsystemHelper.java b/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/AbstractSftpSubsystemHelper.java index 8f0b0ab..dc1123a 100644 --- a/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/AbstractSftpSubsystemHelper.java +++ b/sshd-sftp/src/main/java/org/apache/sshd/sftp/server/AbstractSftpSubsystemHelper.java @@ -79,6 +79,7 @@ import org.apache.sshd.common.session.Session; import org.apache.sshd.common.util.EventListenerUtils; import org.apache.sshd.common.util.GenericUtils; import org.apache.sshd.common.util.MapEntryUtils; +import org.apache.sshd.common.util.MapEntryUtils.MapBuilder; import org.apache.sshd.common.util.MapEntryUtils.NavigableMapBuilder; import org.apache.sshd.common.util.NumberUtils; import org.apache.sshd.common.util.OsUtils; @@ -2238,7 +2239,7 @@ public abstract class AbstractSftpSubsystemHelper accessor.putRemoteFileName(session, this, f, buffer, shortName, true); if (version == SftpConstants.SFTP_V3) { - String longName = SftpHelper.getLongName(shortName, attributes); + String longName = getLongName(f, shortName, attributes); accessor.putRemoteFileName(session, this, f, buffer, longName, false); if (log.isTraceEnabled()) { @@ -2320,6 +2321,18 @@ public abstract class AbstractSftpSubsystemHelper return SftpHelper.getLongName(shortName, attributes); } + protected String getLongName(Path f, String shortName, SftpClient.Attributes attributes) throws IOException { + return getLongName(f, shortName, + MapBuilder.<String, Object> builder() + .put("owner", attributes.getOwner()) + .put("group", attributes.getGroup()) + .put("size", attributes.getSize()) + .put("isDirectory", attributes.isDirectory()) + .put("isSymbolicLink", attributes.isSymbolicLink()) + .put("permissions", SftpHelper.permissionsToAttributes(attributes.getPermissions())) + .put("lastModifiedTime", attributes.getModifyTime()).build()); + } + protected String getShortName(Path f) throws IOException { Path nrm = normalize(f); int count = nrm.getNameCount();