scan_dir is now public

This commit is contained in:
ChristianVisintin
2020-11-28 10:57:55 +01:00
parent 4dc82d2ebb
commit 7cba854260

View File

@@ -113,7 +113,7 @@ impl Localhost {
return Err(HostError::new(HostErrorType::NoSuchFileOrDirectory, None));
}
// Retrieve files for provided path
host.files = match host.scan_dir() {
host.files = match host.scan_dir(host.wrkdir.as_path()) {
Ok(files) => files,
Err(err) => return Err(err),
};
@@ -146,7 +146,7 @@ impl Localhost {
// Update working directory
self.wrkdir = new_dir;
// Scan new directory
self.files = match self.scan_dir() {
self.files = match self.scan_dir(self.wrkdir.as_path()) {
Ok(files) => files,
Err(err) => {
// Restore directory
@@ -170,7 +170,7 @@ impl Localhost {
match std::fs::create_dir(dir_path) {
Ok(_) => {
// Update dir
self.files = match self.scan_dir() {
self.files = match self.scan_dir(self.wrkdir.as_path()) {
Ok(f) => f,
Err(err) => return Err(err)
};
@@ -196,7 +196,7 @@ impl Localhost {
match std::fs::remove_dir_all(f_path) {
Ok(_) => {
// Update dir
self.files = match self.scan_dir() {
self.files = match self.scan_dir(self.wrkdir.as_path()) {
Ok(f) => f,
Err(err) => return Err(err)
};
@@ -215,7 +215,7 @@ impl Localhost {
match std::fs::remove_file(f_path) {
Ok(_) => {
// Update dir
self.files = match self.scan_dir() {
self.files = match self.scan_dir(self.wrkdir.as_path()) {
Ok(f) => f,
Err(err) => return Err(err)
};
@@ -238,7 +238,7 @@ impl Localhost {
match std::fs::rename(abs_path.as_path(), dst_path) {
Ok(_) => {
// Scan dir
self.files = match self.scan_dir() {
self.files = match self.scan_dir(self.wrkdir.as_path()) {
Ok(f) => f,
Err(err) => return Err(err)
};
@@ -285,8 +285,8 @@ impl Localhost {
///
/// Get content of the current directory as a list of fs entry (Windows)
#[cfg(any(unix, macos, linux))]
fn scan_dir(&self) -> Result<Vec<FsEntry>, HostError> {
let entries = match std::fs::read_dir(self.wrkdir.as_path()) {
pub fn scan_dir(&self, dir: &Path) -> Result<Vec<FsEntry>, HostError> {
let entries = match std::fs::read_dir(dir) {
Ok(e) => e,
Err(err) => return Err(HostError::new(HostErrorType::DirNotAccessible, Some(err))),
};
@@ -363,8 +363,8 @@ impl Localhost {
/// Get content of the current directory as a list of fs entry (Windows)
#[cfg(target_os = "windows")]
#[cfg(not(tarpaulin_include))]
fn scan_dir(&self) -> Result<Vec<FsEntry>, HostError> {
let entries = match std::fs::read_dir(self.wrkdir.as_path()) {
fn scan_dir(&self, dir: &Path) -> Result<Vec<FsEntry>, HostError> {
let entries = match std::fs::read_dir(dir) {
Ok(e) => e,
Err(err) => return Err(HostError::new(HostErrorType::DirNotAccessible, Some(err))),
};