Skip to content

Commit db55231

Browse files
authored
[dlt, rtns] Fix libssh deprecation warnings (#7284)
``` /home/tav/frc/wpilib/allwpilib/roborioteamnumbersetter/src/main/native/cpp/SshSession.cpp: In member function ‘void rtns::SshSession::Execute(std::string_view)’: /home/tav/frc/wpilib/allwpilib/roborioteamnumbersetter/src/main/native/cpp/SshSession.cpp:89:44: warning: ‘int ssh_channel_get_exit_status(ssh_channel)’ is deprecated [-Wdeprecated-declarations] 89 | INFO("{} {}", ssh_channel_get_exit_status(channel), cmd); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~ ``` ``` /home/tav/frc/wpilib/allwpilib/roborioteamnumbersetter/src/main/native/cpp/SshSession.cpp:139:44: warning: ‘int ssh_channel_get_exit_status(ssh_channel)’ is deprecated [-Wdeprecated-declarations] 139 | INFO("{} {}", ssh_channel_get_exit_status(channel), cmd); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~ ``` ``` /home/tav/frc/wpilib/allwpilib/roborioteamnumbersetter/src/main/native/cpp/SshSession.cpp:143:46: warning: ‘int ssh_channel_get_exit_status(ssh_channel)’ is deprecated [-Wdeprecated-declarations] 143 | *exitStatus = ssh_channel_get_exit_status(channel); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~ ``` ``` /home/tav/frc/wpilib/allwpilib/datalogtool/src/main/native/cpp/Sftp.cpp:79:33: warning: ‘int sftp_async_read_begin(sftp_file, uint32_t)’ is deprecated [-Wdeprecated-declarations] 79 | int rv = sftp_async_read_begin(m_handle, len); | ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~ ``` ``` /home/tav/frc/wpilib/allwpilib/datalogtool/src/main/native/cpp/Sftp.cpp: In member function ‘size_t sftp::File::AsyncRead(void*, uint32_t, AsyncId)’: /home/tav/frc/wpilib/allwpilib/datalogtool/src/main/native/cpp/Sftp.cpp:87:28: warning: ‘int sftp_async_read(sftp_file, void*, uint32_t, uint32_t)’ is deprecated [-Wdeprecated-declarations] 87 | auto rv = sftp_async_read(m_handle, data, len, id); | ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~ ```
1 parent 03cb3c7 commit db55231

File tree

3 files changed

+15
-26
lines changed

3 files changed

+15
-26
lines changed

datalogtool/src/main/native/cpp/Sftp.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -75,25 +75,6 @@ size_t File::Read(void* buf, uint32_t count) {
7575
return rv;
7676
}
7777

78-
File::AsyncId File::AsyncReadBegin(uint32_t len) const {
79-
int rv = sftp_async_read_begin(m_handle, len);
80-
if (rv < 0) {
81-
throw Exception{m_handle->sftp};
82-
}
83-
return rv;
84-
}
85-
86-
size_t File::AsyncRead(void* data, uint32_t len, AsyncId id) {
87-
auto rv = sftp_async_read(m_handle, data, len, id);
88-
if (rv == SSH_ERROR) {
89-
throw Exception{ssh_get_error(m_handle->sftp->session)};
90-
}
91-
if (rv == SSH_AGAIN) {
92-
return 0;
93-
}
94-
return rv;
95-
}
96-
9778
size_t File::Write(std::span<const uint8_t> data) {
9879
auto rv = sftp_write(m_handle, data.data(), data.size());
9980
if (rv < 0) {

datalogtool/src/main/native/cpp/Sftp.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@ class File {
4747
void SetNonblocking() { sftp_file_set_nonblocking(m_handle); }
4848
void SetBlocking() { sftp_file_set_blocking(m_handle); }
4949

50-
using AsyncId = uint32_t;
51-
5250
size_t Read(void* buf, uint32_t count);
53-
AsyncId AsyncReadBegin(uint32_t len) const;
54-
size_t AsyncRead(void* data, uint32_t len, AsyncId id);
5551
size_t Write(std::span<const uint8_t> data);
5652

5753
void Seek(uint64_t offset);

roborioteamnumbersetter/src/main/native/cpp/SshSession.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,13 @@ void SshSession::Execute(std::string_view cmd) {
8686
ssh_channel_free(channel);
8787
throw SshException(ssh_get_error(m_session));
8888
}
89-
INFO("{} {}", ssh_channel_get_exit_status(channel), cmd);
89+
uint32_t exitCode = 0;
90+
#if LIBSSH_VERSION_MAJOR == 0 && LIBSSH_VERSION_MINOR >= 11
91+
ssh_channel_get_exit_state(channel, &exitCode, nullptr, nullptr);
92+
#else
93+
exitCode = ssh_channel_get_exit_status(channel);
94+
#endif
95+
INFO("{} {}", exitCode, cmd);
9096

9197
// Log output.
9298
char buf[512];
@@ -136,11 +142,17 @@ std::string SshSession::ExecuteResult(std::string_view cmd, int* exitStatus) {
136142
ssh_channel_free(channel);
137143
throw SshException(ssh_get_error(m_session));
138144
}
139-
INFO("{} {}", ssh_channel_get_exit_status(channel), cmd);
145+
uint32_t exitCode = 0;
146+
#if LIBSSH_VERSION_MAJOR == 0 && LIBSSH_VERSION_MINOR >= 11
147+
ssh_channel_get_exit_state(channel, &exitCode, nullptr, nullptr);
148+
#else
149+
ssh_channel_get_exit_status(channel);
150+
#endif
151+
INFO("{} {}", exitCode, cmd);
140152

141153
std::string result;
142154
if (exitStatus) {
143-
*exitStatus = ssh_channel_get_exit_status(channel);
155+
*exitStatus = exitCode;
144156
}
145157

146158
// Log output.

0 commit comments

Comments
 (0)