Skip to content

Sftp server ‘ls’ command timeout#634

Merged
tomaswolf merged 1 commit into
apache:masterfrom
Main-Tomi:master_ls_issue
Nov 15, 2024
Merged

Sftp server ‘ls’ command timeout#634
tomaswolf merged 1 commit into
apache:masterfrom
Main-Tomi:master_ls_issue

Conversation

@Main-Tomi
Copy link
Copy Markdown
Contributor

For the method of writeDirEntry, the method 'getLongName(f, shortName, options);' call 'resolveFileAttributes' to get attrs too. Using the attrs obtained earlier as parameters can reduce the time by half

protected void writeDirEntry(
            int id, DirectoryHandle dir, Map<String, Path> entries, Buffer buffer,
            int index, Path f, String shortName, LinkOption... options)
            throws IOException {
        boolean followLinks = resolvePathResolutionFollowLinks(SftpConstants.SSH_FXP_READDIR, "", f);
        Map<String, ?> attrs = resolveFileAttributes(
                f, SftpConstants.SSH_FILEXFER_ATTR_ALL, !followLinks, options);
        entries.put(shortName, f);

        SftpFileSystemAccessor accessor = getFileSystemAccessor();
        ServerSession session = getServerSession();
        accessor.putRemoteFileName(this, f, buffer, shortName, true);

        int version = getVersion();
        if (version == SftpConstants.SFTP_V3) {
            String longName = getLongName(f, shortName, options);
            accessor.putRemoteFileName(this, f, buffer, longName, false);

            if (log.isTraceEnabled()) {
                log.trace("writeDirEntry({} id={})[{}] - {} [{}]: {}", session, id, index, shortName, longName, attrs);
            }
        } else {
            if (log.isTraceEnabled()) {
                log.trace("writeDirEntry({} id={})[{}] - {}: {}", session, id, index, shortName, attrs);
            }
        }

        writeAttrs(buffer, attrs);
    }

@tomaswolf tomaswolf merged commit 690be26 into apache:master Nov 15, 2024
@tomaswolf
Copy link
Copy Markdown
Member

Good catch; thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants