This commit is contained in:
Michael Doronin
2020-10-28 16:03:52 +03:00
parent e86db16840
commit 104431b0c4
2 changed files with 21 additions and 24 deletions

View File

@@ -80,7 +80,7 @@ const SMBC_TRUE: smbc_bool = 1;
pub struct SmbClient<'a> {
ctx: *mut SMBCCTX,
#[allow(dead_code)]
auth_fn: &'a for<'b> Fn(&'b str, &'b str) -> (Cow<'a, str>, Cow<'a, str>, Cow<'a, str>),
auth_fn: &'a dyn for<'b> Fn(&'b str, &'b str) -> (Cow<'a, str>, Cow<'a, str>, Cow<'a, str>),
}
// {{{2
@@ -211,10 +211,9 @@ impl<'a> SmbClient<'a> {
let path = cstring(path)?;
trace!(target: "smbc", "opening {:?} with {:?}", path, open_fn);
unsafe {
let fd = result_from_ptr_mut(open_fn(self.ctx,
path.as_ptr(),
try!(options.to_flags()),
options.to_flags()?,
options.mode))?;
if (fd as i64) < 0 {
trace!(target: "smbc", "neg fd");
@@ -224,7 +223,6 @@ impl<'a> SmbClient<'a> {
fd: fd,
})
}
}
/// Open read-only [`SmbFile`](struct.SmbFile.html) defined by SMB `path`.
///
@@ -272,9 +270,8 @@ impl<'a> SmbClient<'a> {
#[doc(hidden)]
/// Get metadata for file at `path`
pub fn metadata<P: AsRef<str>>(&self, path: P) -> Result<()> {
let stat_fn = try_ufn!(smbc_getFunctionStat <- self);
let path = cstring(path)?;
let _stat_fn = try_ufn!(smbc_getFunctionStat <- self);
let _path = cstring(path)?;
unimplemented!();
}
@@ -282,7 +279,7 @@ impl<'a> SmbClient<'a> {
pub fn create_dir<P: AsRef<str>>(&self, path: P) -> Result<()> {
let mkdir_fn = try_ufn!(smbc_getFunctionMkdir <- self);
let path = cstring(path)?;
to_result_with_le(unsafe { mkdir_fn(self.ctx, path.as_ptr(), 0o755) })?;
to_result_with_le(mkdir_fn(self.ctx, path.as_ptr(), 0o755))?;
Ok(())
}
@@ -296,7 +293,7 @@ impl<'a> SmbClient<'a> {
pub fn remove_dir<P: AsRef<str>>(&self, path: P) -> Result<()> {
let rmdir_fn = try_ufn!(smbc_getFunctionRmdir <- self);
let path = cstring(path)?;
to_result_with_le(unsafe { rmdir_fn(self.ctx, path.as_ptr()) })?;
to_result_with_le(rmdir_fn(self.ctx, path.as_ptr()))?;
Ok(())
}
} // 2}}}
@@ -426,12 +423,12 @@ impl<'a, 'b> Read for SmbFile<'a, 'b> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
trace!(target: "smbc", "reading file to buf [{:?};{}]", buf.as_ptr(), buf.len());
let read_fn = try_ufn!(smbc_getFunctionRead <- self.smbc);
let bytes_read = to_result_with_le(unsafe {
let bytes_read = to_result_with_le(
read_fn(self.smbc.ctx,
self.fd,
buf.as_mut_ptr() as *mut c_void,
buf.len() as _)
})?;
)?;
Ok(bytes_read as usize)
}
} // }}}
@@ -441,12 +438,12 @@ impl<'a, 'b> Write for SmbFile<'a, 'b> {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
trace!(target: "smbc", "writing buf [{:?};{}] to file", buf.as_ptr(), buf.len());
let write_fn = try_ufn!(smbc_getFunctionWrite <- self.smbc);
let bytes_wrote = to_result_with_le(unsafe {
let bytes_wrote = to_result_with_le(
write_fn(self.smbc.ctx,
self.fd,
buf.as_ptr() as *const c_void,
buf.len() as _)
})?;
)?;
Ok(bytes_wrote as usize)
}
@@ -466,7 +463,7 @@ impl<'a, 'b> Seek for SmbFile<'a, 'b> {
SeekFrom::End(p) => (libc::SEEK_END, p as off_t),
SeekFrom::Current(p) => (libc::SEEK_CUR, p as off_t),
};
let res = to_result_with_errno(unsafe { lseek_fn(self.smbc.ctx, self.fd, off, whence) }, libc::EINVAL)?;
let res = to_result_with_errno(lseek_fn(self.smbc.ctx, self.fd, off, whence), libc::EINVAL)?;
Ok(res as u64)
}
} // }}}

View File

@@ -16,7 +16,7 @@
// You should have received a copy of the GNU General Public License
// along with smbc. If not, see <http://www.gnu.org/licenses/>.
use libc::{self, c_char, c_int};
use libc::{c_char, c_int};
use std::borrow::Cow;
use std::ffi::{CStr, CString};