Compare commits

...

3 Commits

Author SHA1 Message Date
03879ee42e removed debug stuff 2021-11-27 17:29:36 +01:00
ade1518d48 Finished up Read directory 2021-11-27 16:22:12 +01:00
03844f85d2 Removed git actions 2021-11-27 00:05:58 +01:00
2 changed files with 22 additions and 142 deletions

View File

@@ -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

View File

@@ -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`.