summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWez Furlong <wez@wezfurlong.org>2019-09-02 13:48:16 -0700
committerWez Furlong <wez@wezfurlong.org>2019-09-15 16:36:32 -0700
commitea200c833395fcfee73ff1dfc8cc16f5aba86a19 (patch)
tree2fb48b6f747256f29b69580b7e9b34eab7a4bcc0 /src
parentef5685e40c96c1fd9552ad4692a5edd2aa3cb545 (diff)
downloadssh2-rs-ea200c833395fcfee73ff1dfc8cc16f5aba86a19.zip
replace use of try! with ? operator
This fixes the CI build with nightly, as we have deny(warnings) enabled.
Diffstat (limited to 'src')
-rw-r--r--src/agent.rs2
-rw-r--r--src/channel.rs4
-rw-r--r--src/knownhosts.rs10
-rw-r--r--src/session.rs44
-rw-r--r--src/sftp.rs38
5 files changed, 49 insertions, 49 deletions
diff --git a/src/agent.rs b/src/agent.rs
index ad1b863..88c84f5 100644
--- a/src/agent.rs
+++ b/src/agent.rs
@@ -70,7 +70,7 @@ impl Agent {
/// Attempt public key authentication with the help of ssh-agent.
pub fn userauth(&self, username: &str, identity: &PublicKey) -> Result<(), Error> {
- let username = try!(CString::new(username));
+ let username = CString::new(username)?;
unsafe {
self.sess.rc(raw::libssh2_agent_userauth(
self.raw,
diff --git a/src/channel.rs b/src/channel.rs
index 69b535a..3beece6 100644
--- a/src/channel.rs
+++ b/src/channel.rs
@@ -263,7 +263,7 @@ impl Channel {
&mut lang,
&mut langlen,
);
- try!(self.sess.rc(rc));
+ self.sess.rc(rc)?;
return Ok(ExitSignal {
exit_signal: convert(self, sig, siglen),
error_message: convert(self, msg, msglen),
@@ -325,7 +325,7 @@ impl Channel {
&mut ret,
)
};
- try!(self.sess.rc(rc));
+ self.sess.rc(rc)?;
Ok(ret as u64)
}
diff --git a/src/knownhosts.rs b/src/knownhosts.rs
index d2e507e..fcf5b5e 100644
--- a/src/knownhosts.rs
+++ b/src/knownhosts.rs
@@ -79,10 +79,10 @@ impl KnownHosts {
/// Reads a collection of known hosts from a specified file and adds them to
/// the collection of known hosts.
pub fn read_file(&mut self, file: &Path, kind: KnownHostFileKind) -> Result<u32, Error> {
- let file = try!(CString::new(try!(util::path2bytes(file))));
+ let file = CString::new(util::path2bytes(file)?)?;
let n = unsafe { raw::libssh2_knownhost_readfile(self.raw, file.as_ptr(), kind as c_int) };
if n < 0 {
- try!(self.sess.rc(n))
+ self.sess.rc(n)?
}
Ok(n as u32)
}
@@ -102,7 +102,7 @@ impl KnownHosts {
/// Writes all the known hosts to the specified file using the specified
/// file format.
pub fn write_file(&self, file: &Path, kind: KnownHostFileKind) -> Result<(), Error> {
- let file = try!(CString::new(try!(util::path2bytes(file))));
+ let file = CString::new(util::path2bytes(file)?)?;
let n = unsafe { raw::libssh2_knownhost_writefile(self.raw, file.as_ptr(), kind as c_int) };
self.sess.rc(n)
}
@@ -126,7 +126,7 @@ impl KnownHosts {
// + 1 for the trailing zero
v.reserve(outlen as usize + 1);
} else {
- try!(self.sess.rc(rc));
+ self.sess.rc(rc)?;
v.set_len(outlen as usize);
break;
}
@@ -202,7 +202,7 @@ impl KnownHosts {
comment: &str,
fmt: ::KnownHostKeyFormat,
) -> Result<(), Error> {
- let host = try!(CString::new(host));
+ let host = CString::new(host)?;
let flags =
raw::LIBSSH2_KNOWNHOST_TYPE_PLAIN | raw::LIBSSH2_KNOWNHOST_KEYENC_RAW | (fmt as c_int);
unsafe {
diff --git a/src/session.rs b/src/session.rs
index d0049c5..2b522ff 100644
--- a/src/session.rs
+++ b/src/session.rs
@@ -121,7 +121,7 @@ impl Session {
/// corresponding to the protocol and libssh2 version will be sent by
/// default.
pub fn set_banner(&self, banner: &str) -> Result<(), Error> {
- let banner = try!(CString::new(banner));
+ let banner = CString::new(banner)?;
unsafe {
self.rc(raw::libssh2_session_banner_set(
self.inner.raw,
@@ -390,11 +390,11 @@ impl Session {
/// control is needed than this method offers, it is recommended to use
/// `agent` directly to control how the identity is found.
pub fn userauth_agent(&self, username: &str) -> Result<(), Error> {
- let mut agent = try!(self.agent());
- try!(agent.connect());
- try!(agent.list_identities());
+ let mut agent = self.agent()?;
+ agent.connect()?;
+ agent.list_identities()?;
let identity = match agent.identities().next() {
- Some(identity) => try!(identity),
+ Some(identity) => identity?,
None => {
return Err(Error::new(
raw::LIBSSH2_ERROR_INVAL as c_int,
@@ -415,12 +415,12 @@ impl Session {
passphrase: Option<&str>,
) -> Result<(), Error> {
let pubkey = match pubkey {
- Some(s) => Some(try!(CString::new(try!(util::path2bytes(s))))),
+ Some(s) => Some(CString::new(util::path2bytes(s)?)?),
None => None,
};
- let privatekey = try!(CString::new(try!(util::path2bytes(privatekey))));
+ let privatekey = CString::new(util::path2bytes(privatekey)?)?;
let passphrase = match passphrase {
- Some(s) => Some(try!(CString::new(s))),
+ Some(s) => Some(CString::new(s)?),
None => None,
};
self.rc(unsafe {
@@ -452,13 +452,13 @@ impl Session {
passphrase: Option<&str>,
) -> Result<(), Error> {
let (pubkeydata, pubkeydata_len) = match pubkeydata {
- Some(s) => (Some(try!(CString::new(s))), s.len()),
+ Some(s) => (Some(CString::new(s)?), s.len()),
None => (None, 0),
};
let privatekeydata_len = privatekeydata.len();
- let privatekeydata = try!(CString::new(privatekeydata));
+ let privatekeydata = CString::new(privatekeydata)?;
let passphrase = match passphrase {
- Some(s) => Some(try!(CString::new(s))),
+ Some(s) => Some(CString::new(s)?),
None => None,
};
self.rc(unsafe {
@@ -492,10 +492,10 @@ impl Session {
hostname: &str,
local_username: Option<&str>,
) -> Result<(), Error> {
- let publickey = try!(CString::new(try!(util::path2bytes(publickey))));
- let privatekey = try!(CString::new(try!(util::path2bytes(privatekey))));
+ let publickey = CString::new(util::path2bytes(publickey)?)?;
+ let privatekey = CString::new(util::path2bytes(privatekey)?)?;
let passphrase = match passphrase {
- Some(s) => Some(try!(CString::new(s))),
+ Some(s) => Some(CString::new(s)?),
None => None,
};
let local_username = match local_username {
@@ -540,7 +540,7 @@ impl Session {
/// and may be an empty string.
pub fn auth_methods(&self, username: &str) -> Result<&str, Error> {
let len = username.len();
- let username = try!(CString::new(username));
+ let username = CString::new(username)?;
unsafe {
let ret = raw::libssh2_userauth_list(self.inner.raw, username.as_ptr(), len as c_uint);
if ret.is_null() {
@@ -562,7 +562,7 @@ impl Session {
/// will be ignored and not sent to the remote host during protocol
/// negotiation.
pub fn method_pref(&self, method_type: MethodType, prefs: &str) -> Result<(), Error> {
- let prefs = try!(CString::new(prefs));
+ let prefs = CString::new(prefs)?;
unsafe {
self.rc(raw::libssh2_session_method_pref(
self.inner.raw,
@@ -654,8 +654,8 @@ impl Session {
src: Option<(&str, u16)>,
) -> Result<Channel, Error> {
let (shost, sport) = src.unwrap_or(("127.0.0.1", 22));
- let host = try!(CString::new(host));
- let shost = try!(CString::new(shost));
+ let host = CString::new(host)?;
+ let shost = CString::new(shost)?;
unsafe {
let ret = raw::libssh2_channel_direct_tcpip_ex(
self.inner.raw,
@@ -698,7 +698,7 @@ impl Session {
/// sent over the returned channel. Some stat information is also returned
/// about the remote file to prepare for receiving the file.
pub fn scp_recv(&self, path: &Path) -> Result<(Channel, ScpFileStat), Error> {
- let path = try!(CString::new(try!(util::path2bytes(path))));
+ let path = CString::new(util::path2bytes(path)?)?;
unsafe {
let mut sb: raw::libssh2_struct_stat = mem::zeroed();
let ret = raw::libssh2_scp_recv2(self.inner.raw, path.as_ptr(), &mut sb);
@@ -729,7 +729,7 @@ impl Session {
size: u64,
times: Option<(u64, u64)>,
) -> Result<Channel, Error> {
- let path = try!(CString::new(try!(util::path2bytes(remote_path))));
+ let path = CString::new(util::path2bytes(remote_path)?)?;
let (mtime, atime) = times.unwrap_or((0, 0));
unsafe {
let ret = raw::libssh2_scp_send64(
@@ -889,8 +889,8 @@ impl Session {
lang: Option<&str>,
) -> Result<(), Error> {
let reason = reason.unwrap_or(ByApplication) as c_int;
- let description = try!(CString::new(description));
- let lang = try!(CString::new(lang.unwrap_or("")));
+ let description = CString::new(description)?;
+ let lang = CString::new(lang.unwrap_or(""))?;
unsafe {
self.rc(raw::libssh2_session_disconnect_ex(
self.inner.raw,
diff --git a/src/sftp.rs b/src/sftp.rs
index 37f8dfd..396359b 100644
--- a/src/sftp.rs
+++ b/src/sftp.rs
@@ -125,7 +125,7 @@ impl Sftp {
mode: i32,
open_type: OpenType,
) -> Result<File, Error> {
- let filename = try!(util::path2bytes(filename));
+ let filename = util::path2bytes(filename)?;
unsafe {
let ret = raw::libssh2_sftp_open_ex(
self.raw,
@@ -168,7 +168,7 @@ impl Sftp {
/// The returned paths are all joined with `dirname` when returned, and the
/// paths `.` and `..` are filtered out of the returned list.
pub fn readdir(&self, dirname: &Path) -> Result<Vec<(PathBuf, FileStat)>, Error> {
- let mut dir = try!(self.opendir(dirname));
+ let mut dir = self.opendir(dirname)?;
let mut ret = Vec::new();
loop {
match dir.readdir() {
@@ -188,7 +188,7 @@ impl Sftp {
/// Create a directory on the remote file system.
pub fn mkdir(&self, filename: &Path, mode: i32) -> Result<(), Error> {
- let filename = try!(util::path2bytes(filename));
+ let filename = util::path2bytes(filename)?;
self.rc(unsafe {
raw::libssh2_sftp_mkdir_ex(
self.raw,
@@ -201,7 +201,7 @@ impl Sftp {
/// Remove a directory from the remote file system.
pub fn rmdir(&self, filename: &Path) -> Result<(), Error> {
- let filename = try!(util::path2bytes(filename));
+ let filename = util::path2bytes(filename)?;
self.rc(unsafe {
raw::libssh2_sftp_rmdir_ex(
self.raw,
@@ -213,7 +213,7 @@ impl Sftp {
/// Get the metadata for a file, performed by stat(2)
pub fn stat(&self, filename: &Path) -> Result<FileStat, Error> {
- let filename = try!(util::path2bytes(filename));
+ let filename = util::path2bytes(filename)?;
unsafe {
let mut ret = mem::zeroed();
let rc = raw::libssh2_sftp_stat_ex(
@@ -223,14 +223,14 @@ impl Sftp {
raw::LIBSSH2_SFTP_STAT,
&mut ret,
);
- try!(self.rc(rc));
+ self.rc(rc)?;
Ok(FileStat::from_raw(&ret))
}
}
/// Get the metadata for a file, performed by lstat(2)
pub fn lstat(&self, filename: &Path) -> Result<FileStat, Error> {
- let filename = try!(util::path2bytes(filename));
+ let filename = util::path2bytes(filename)?;
unsafe {
let mut ret = mem::zeroed();
let rc = raw::libssh2_sftp_stat_ex(
@@ -240,14 +240,14 @@ impl Sftp {
raw::LIBSSH2_SFTP_LSTAT,
&mut ret,
);
- try!(self.rc(rc));
+ self.rc(rc)?;
Ok(FileStat::from_raw(&ret))
}
}
/// Set the metadata for a file.
pub fn setstat(&self, filename: &Path, stat: FileStat) -> Result<(), Error> {
- let filename = try!(util::path2bytes(filename));
+ let filename = util::path2bytes(filename)?;
self.rc(unsafe {
let mut raw = stat.raw();
raw::libssh2_sftp_stat_ex(
@@ -262,8 +262,8 @@ impl Sftp {
/// Create a symlink at `target` pointing at `path`.
pub fn symlink(&self, path: &Path, target: &Path) -> Result<(), Error> {
- let path = try!(util::path2bytes(path));
- let target = try!(util::path2bytes(target));
+ let path = util::path2bytes(path)?;
+ let target = util::path2bytes(target)?;
self.rc(unsafe {
raw::libssh2_sftp_symlink_ex(
self.raw,
@@ -287,7 +287,7 @@ impl Sftp {
}
fn readlink_op(&self, path: &Path, op: c_int) -> Result<PathBuf, Error> {
- let path = try!(util::path2bytes(path));
+ let path = util::path2bytes(path)?;
let mut ret = Vec::<u8>::with_capacity(128);
let mut rc;
loop {
@@ -331,8 +331,8 @@ impl Sftp {
pub fn rename(&self, src: &Path, dst: &Path, flags: Option<RenameFlags>) -> Result<(), Error> {
let flags =
flags.unwrap_or(RenameFlags::ATOMIC | RenameFlags::OVERWRITE | RenameFlags::NATIVE);
- let src = try!(util::path2bytes(src));
- let dst = try!(util::path2bytes(dst));
+ let src = util::path2bytes(src)?;
+ let dst = util::path2bytes(dst)?;
self.rc(unsafe {
raw::libssh2_sftp_rename_ex(
self.raw,
@@ -347,7 +347,7 @@ impl Sftp {
/// Remove a file on the remote filesystem
pub fn unlink(&self, file: &Path) -> Result<(), Error> {
- let file = try!(util::path2bytes(file));
+ let file = util::path2bytes(file)?;
self.rc(unsafe {
raw::libssh2_sftp_unlink_ex(self.raw, file.as_ptr() as *const _, file.len() as c_uint)
})
@@ -399,9 +399,8 @@ impl<'sftp> File<'sftp> {
pub fn stat(&mut self) -> Result<FileStat, Error> {
unsafe {
let mut ret = mem::zeroed();
- try!(self
- .sftp
- .rc(raw::libssh2_sftp_fstat_ex(self.raw, &mut ret, 0)));
+ self.sftp
+ .rc(raw::libssh2_sftp_fstat_ex(self.raw, &mut ret, 0))?;
Ok(FileStat::from_raw(&ret))
}
}
@@ -410,7 +409,8 @@ impl<'sftp> File<'sftp> {
pub fn statvfs(&mut self) -> Result<raw::LIBSSH2_SFTP_STATVFS, Error> {
unsafe {
let mut ret = mem::zeroed();
- try!(self.sftp.rc(raw::libssh2_sftp_fstatvfs(self.raw, &mut ret)));
+ self.sftp
+ .rc(raw::libssh2_sftp_fstatvfs(self.raw, &mut ret))?;
Ok(ret)
}
}