Cleanup
This commit is contained in:
43
src/smbc.rs
43
src/smbc.rs
@@ -80,7 +80,7 @@ const SMBC_TRUE: smbc_bool = 1;
|
|||||||
pub struct SmbClient<'a> {
|
pub struct SmbClient<'a> {
|
||||||
ctx: *mut SMBCCTX,
|
ctx: *mut SMBCCTX,
|
||||||
#[allow(dead_code)]
|
#[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
|
// {{{2
|
||||||
@@ -211,19 +211,17 @@ impl<'a> SmbClient<'a> {
|
|||||||
let path = cstring(path)?;
|
let path = cstring(path)?;
|
||||||
trace!(target: "smbc", "opening {:?} with {:?}", path, open_fn);
|
trace!(target: "smbc", "opening {:?} with {:?}", path, open_fn);
|
||||||
|
|
||||||
unsafe {
|
let fd = result_from_ptr_mut(open_fn(self.ctx,
|
||||||
let fd = result_from_ptr_mut(open_fn(self.ctx,
|
path.as_ptr(),
|
||||||
path.as_ptr(),
|
options.to_flags()?,
|
||||||
try!(options.to_flags()),
|
options.mode))?;
|
||||||
options.mode))?;
|
if (fd as i64) < 0 {
|
||||||
if (fd as i64) < 0 {
|
trace!(target: "smbc", "neg fd");
|
||||||
trace!(target: "smbc", "neg fd");
|
|
||||||
}
|
|
||||||
Ok(SmbFile {
|
|
||||||
smbc: &self,
|
|
||||||
fd: fd,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
Ok(SmbFile {
|
||||||
|
smbc: &self,
|
||||||
|
fd: fd,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Open read-only [`SmbFile`](struct.SmbFile.html) defined by SMB `path`.
|
/// Open read-only [`SmbFile`](struct.SmbFile.html) defined by SMB `path`.
|
||||||
@@ -272,9 +270,8 @@ impl<'a> SmbClient<'a> {
|
|||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
/// Get metadata for file at `path`
|
/// Get metadata for file at `path`
|
||||||
pub fn metadata<P: AsRef<str>>(&self, path: P) -> Result<()> {
|
pub fn metadata<P: AsRef<str>>(&self, path: P) -> Result<()> {
|
||||||
let stat_fn = try_ufn!(smbc_getFunctionStat <- self);
|
let _stat_fn = try_ufn!(smbc_getFunctionStat <- self);
|
||||||
let path = cstring(path)?;
|
let _path = cstring(path)?;
|
||||||
|
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,7 +279,7 @@ impl<'a> SmbClient<'a> {
|
|||||||
pub fn create_dir<P: AsRef<str>>(&self, path: P) -> Result<()> {
|
pub fn create_dir<P: AsRef<str>>(&self, path: P) -> Result<()> {
|
||||||
let mkdir_fn = try_ufn!(smbc_getFunctionMkdir <- self);
|
let mkdir_fn = try_ufn!(smbc_getFunctionMkdir <- self);
|
||||||
let path = cstring(path)?;
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,7 +293,7 @@ impl<'a> SmbClient<'a> {
|
|||||||
pub fn remove_dir<P: AsRef<str>>(&self, path: P) -> Result<()> {
|
pub fn remove_dir<P: AsRef<str>>(&self, path: P) -> Result<()> {
|
||||||
let rmdir_fn = try_ufn!(smbc_getFunctionRmdir <- self);
|
let rmdir_fn = try_ufn!(smbc_getFunctionRmdir <- self);
|
||||||
let path = cstring(path)?;
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
} // 2}}}
|
} // 2}}}
|
||||||
@@ -426,12 +423,12 @@ impl<'a, 'b> Read for SmbFile<'a, 'b> {
|
|||||||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||||||
trace!(target: "smbc", "reading file to buf [{:?};{}]", buf.as_ptr(), buf.len());
|
trace!(target: "smbc", "reading file to buf [{:?};{}]", buf.as_ptr(), buf.len());
|
||||||
let read_fn = try_ufn!(smbc_getFunctionRead <- self.smbc);
|
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,
|
read_fn(self.smbc.ctx,
|
||||||
self.fd,
|
self.fd,
|
||||||
buf.as_mut_ptr() as *mut c_void,
|
buf.as_mut_ptr() as *mut c_void,
|
||||||
buf.len() as _)
|
buf.len() as _)
|
||||||
})?;
|
)?;
|
||||||
Ok(bytes_read as usize)
|
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> {
|
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
||||||
trace!(target: "smbc", "writing buf [{:?};{}] to file", buf.as_ptr(), buf.len());
|
trace!(target: "smbc", "writing buf [{:?};{}] to file", buf.as_ptr(), buf.len());
|
||||||
let write_fn = try_ufn!(smbc_getFunctionWrite <- self.smbc);
|
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,
|
write_fn(self.smbc.ctx,
|
||||||
self.fd,
|
self.fd,
|
||||||
buf.as_ptr() as *const c_void,
|
buf.as_ptr() as *const c_void,
|
||||||
buf.len() as _)
|
buf.len() as _)
|
||||||
})?;
|
)?;
|
||||||
Ok(bytes_wrote as usize)
|
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::End(p) => (libc::SEEK_END, p as off_t),
|
||||||
SeekFrom::Current(p) => (libc::SEEK_CUR, 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)
|
Ok(res as u64)
|
||||||
}
|
}
|
||||||
} // }}}
|
} // }}}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with smbc. If not, see <http://www.gnu.org/licenses/>.
|
// 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::borrow::Cow;
|
||||||
use std::ffi::{CStr, CString};
|
use std::ffi::{CStr, CString};
|
||||||
|
|||||||
Reference in New Issue
Block a user