Compare commits
3 Commits
c6f0450d61
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 03879ee42e | |||
| ade1518d48 | |||
| 03844f85d2 |
99
.github/workflows/ci.yml
vendored
99
.github/workflows/ci.yml
vendored
@@ -1,99 +0,0 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
- push
|
||||
- pull_request
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
jobs:
|
||||
fmt:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
profile: minimal
|
||||
toolchain: stable
|
||||
override: true
|
||||
components: rustfmt
|
||||
- uses: Swatinem/rust-cache@v1
|
||||
- name: Run cargo fmt
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: fmt
|
||||
args: --all -- --check
|
||||
|
||||
clippy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
profile: minimal
|
||||
toolchain: stable
|
||||
override: true
|
||||
components: clippy
|
||||
- uses: Swatinem/rust-cache@v1
|
||||
- name: Run cargo clippy
|
||||
uses: actions-rs/clippy@master
|
||||
with:
|
||||
args: --all-features
|
||||
|
||||
build-linux:
|
||||
name: Build on Linux with Rust ${{ matrix.rust }}
|
||||
runs-on: ubuntu-latest
|
||||
needs:
|
||||
- fmt
|
||||
- clippy
|
||||
strategy:
|
||||
matrix:
|
||||
rust:
|
||||
- stable
|
||||
- beta
|
||||
- 1.42 # MSRV
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
profile: minimal
|
||||
toolchain: ${{ matrix.rust }}
|
||||
override: true
|
||||
- uses: Swatinem/rust-cache@v1
|
||||
- name: Install libsmbclient-dev & pkg-config
|
||||
run: sudo apt -y install libsmbclient-dev pkg-config
|
||||
- name: Run cargo check
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: check
|
||||
- name: Run cargo build
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: build
|
||||
args: --verbose
|
||||
|
||||
build-macos:
|
||||
name: Build on MacOS with Rust ${{ matrix.rust }}
|
||||
runs-on: macos-latest
|
||||
needs:
|
||||
- build-linux
|
||||
strategy:
|
||||
matrix:
|
||||
rust:
|
||||
- stable
|
||||
- beta
|
||||
- 1.42 # MSRV
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
profile: minimal
|
||||
toolchain: ${{ matrix.rust }}
|
||||
override: true
|
||||
- uses: Swatinem/rust-cache@v1
|
||||
- name: Build
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: build
|
||||
args: --verbose
|
||||
65
src/smbc.rs
65
src/smbc.rs
@@ -125,10 +125,10 @@ pub struct SmbFile<'a: 'b, 'b> {
|
||||
fd: *mut SMBCFILE,
|
||||
}
|
||||
|
||||
pub struct SmbDirectory<'a: 'b, 'b> {
|
||||
smbc: &'b SmbClient<'a>,
|
||||
pub fd: *mut smbc_dirent,
|
||||
}
|
||||
// pub struct SmbDirectory<'a: 'b, 'b> {
|
||||
// smbc: &'b SmbClient<'a>,
|
||||
// pub dir_struct: Vec<&str>,
|
||||
// }
|
||||
// 1}}}
|
||||
|
||||
/// Default (dummy) credential `WORKGROUP\guest` with empty password
|
||||
@@ -213,7 +213,7 @@ impl<'a> SmbClient<'a> {
|
||||
|
||||
/// Opens [`SmbFile`](struct.SmbFile.html) defined by SMB `path` with `options`.
|
||||
///
|
||||
/// See [OpenOptions](struct.OpenOptions.html).
|
||||
/// See [OpenOptions](struct.OpenOptions.html).Vec<smbc_dirent>
|
||||
pub fn open_with<'b, P: AsRef<str>>(
|
||||
&'b self,
|
||||
path: P,
|
||||
@@ -238,58 +238,37 @@ impl<'a> SmbClient<'a> {
|
||||
Ok(SmbFile { smbc: &self, fd })
|
||||
}
|
||||
|
||||
/// READ DIR
|
||||
///
|
||||
/// See [OpenOptions](struct.OpenOptions.html).
|
||||
pub fn read_dir<'b, P: AsRef<str>>(&'b self,path: P) -> Result<SmbDirectory<'a, 'b>>{
|
||||
|
||||
let read_dir_fn = self.get_fn(smbc_getFunctionReaddir)?;
|
||||
let open_dir_fn = self.get_fn(smbc_getFunctionOpendir)?;
|
||||
|
||||
let path = cstring(path)?;
|
||||
trace!(target: "smbc", "opening {:?} with {:?}", path, read_dir_fn);
|
||||
|
||||
let dir = result_from_ptr_mut(open_dir_fn(self.ctx, path.as_ptr()))?;
|
||||
let fd = result_from_ptr_mut(read_dir_fn(self.ctx, dir))?;
|
||||
if (fd as i64) < 0 {
|
||||
trace!(target: "smbc", "neg fd");
|
||||
}
|
||||
Ok(SmbDirectory { smbc: &self, fd })
|
||||
}
|
||||
|
||||
/// READ DIR
|
||||
///
|
||||
/// See [OpenOptions](struct.OpenOptions.html).
|
||||
pub fn read_dirents<'b, P: AsRef<str>>(&'b self,path: P) -> Result<SmbDirectory<'a, 'b>>{
|
||||
pub fn read_directory<'b, P: AsRef<str>>(&'b self,path: P) -> Result<Vec<String>>{
|
||||
|
||||
let read_dir_fn = self.get_fn(smbc_getFunctionReaddir)?;
|
||||
let open_dir_fn = self.get_fn(smbc_getFunctionOpendir)?;
|
||||
let get_dents_fn = self.get_fn(smbc_getFunctionGetdents)?;
|
||||
|
||||
let path = cstring(path)?;
|
||||
trace!(target: "smbc", "opening {:?} with {:?}", path, read_dir_fn);
|
||||
|
||||
let dir = result_from_ptr_mut(open_dir_fn(self.ctx, path.as_ptr()))?;
|
||||
let fd = result_from_ptr_mut(read_dir_fn(self.ctx, dir)).expect("Can't read file");
|
||||
let _fd = result_from_ptr_mut(read_dir_fn(self.ctx, dir)).expect("Can't read file");
|
||||
let _fd = result_from_ptr_mut(read_dir_fn(self.ctx, dir)).expect("Can't read file");
|
||||
let _fd = result_from_ptr_mut(read_dir_fn(self.ctx, dir)).expect("Can't read file");
|
||||
let _fd = result_from_ptr_mut(read_dir_fn(self.ctx, dir)).expect("Can't read file");
|
||||
let _fd = result_from_ptr_mut(read_dir_fn(self.ctx, dir)).expect("Can't read file");
|
||||
let _fd = result_from_ptr_mut(read_dir_fn(self.ctx, dir)).is_err();
|
||||
println!("{}", _fd);
|
||||
|
||||
//let mut return_dirs= HashSet::new();
|
||||
let mut return_dirs= Vec::new();
|
||||
|
||||
//Returns number of read bytes
|
||||
//let out_test = get_dents_fn(self.ctx, dir, fd, 200);
|
||||
if (fd as i64) < 0 {
|
||||
trace!(target: "smbc", "neg fd");
|
||||
}
|
||||
// let out_test = get_dents_fn(self.ctx, dir, fd, 2);
|
||||
// let out_test = get_dents_fn(self.ctx, dir, fd, 2);
|
||||
//println!("{}", out_test);
|
||||
use std::ffi::CStr;
|
||||
loop {
|
||||
match result_from_ptr_mut(read_dir_fn(self.ctx, dir)) {
|
||||
Ok(dir_struct) => {
|
||||
unsafe{
|
||||
let c_str: &CStr = CStr::from_ptr(&(*dir_struct).name[0]) ;
|
||||
let test = Cow::Borrowed(c_str.to_str().unwrap()).into_owned();
|
||||
return_dirs.push(test);
|
||||
}
|
||||
}
|
||||
Err(_) => break
|
||||
};
|
||||
};
|
||||
|
||||
Ok(SmbDirectory { smbc: &self, fd })
|
||||
Ok(return_dirs )
|
||||
}
|
||||
|
||||
/// Open read-only [`SmbFile`](struct.SmbFile.html) defined by SMB `path`.
|
||||
|
||||
Reference in New Issue
Block a user