///////////////////////////////////////////////////////
| 857 | |
| 858 | //////////////////////////////////////////////////////////// |
| 859 | Sftp::PathResult Sftp::resolvePath(const std::filesystem::path& path, const TimeoutWithPredicate& timeout) |
| 860 | { |
| 861 | // Check if we already cached the result for the home path |
| 862 | if ((path == ".") && !m_impl->cachedHomePath.empty()) |
| 863 | return {Result(Result::Value::Success), m_impl->cachedHomePath}; |
| 864 | |
| 865 | const auto pathString = pathToUtf8(path); |
| 866 | std::array<char, 4096> buffer{}; |
| 867 | const auto result = m_impl->waitForOperationComplete( |
| 868 | [&] |
| 869 | { |
| 870 | return libssh2_sftp_symlink_ex(m_impl->sftpSession.get(), |
| 871 | pathString.data(), |
| 872 | static_cast<unsigned int>(pathString.size()), |
| 873 | buffer.data(), |
| 874 | static_cast<unsigned int>(buffer.size()), |
| 875 | LIBSSH2_SFTP_REALPATH); |
| 876 | }, |
| 877 | timeout); |
| 878 | |
| 879 | if (result == LIBSSH2_ERROR_EAGAIN) |
| 880 | return {Result(Result::Value::Timeout), {}}; |
| 881 | |
| 882 | if (result < 0) |
| 883 | return {makeError(m_impl->ssh2Session.get(), m_impl->sftpSession.get()), {}}; |
| 884 | |
| 885 | // The path from libssh2 is UTF-8 encoded, convert before constructing filesystem::path |
| 886 | const auto resolvedPath = pathFromUtf8({buffer.data(), static_cast<std::size_t>(result)}); |
| 887 | |
| 888 | // Cache the result for the home path |
| 889 | if (path == ".") |
| 890 | m_impl->cachedHomePath = resolvedPath; |
| 891 | |
| 892 | return {Result(Result::Value::Success), resolvedPath}; |
| 893 | } |
| 894 | |
| 895 | |
| 896 | //////////////////////////////////////////////////////////// |
nothing calls this directly
no test coverage detected