mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
scan_dir is now public
This commit is contained in:
@@ -113,7 +113,7 @@ impl Localhost {
|
|||||||
return Err(HostError::new(HostErrorType::NoSuchFileOrDirectory, None));
|
return Err(HostError::new(HostErrorType::NoSuchFileOrDirectory, None));
|
||||||
}
|
}
|
||||||
// Retrieve files for provided path
|
// Retrieve files for provided path
|
||||||
host.files = match host.scan_dir() {
|
host.files = match host.scan_dir(host.wrkdir.as_path()) {
|
||||||
Ok(files) => files,
|
Ok(files) => files,
|
||||||
Err(err) => return Err(err),
|
Err(err) => return Err(err),
|
||||||
};
|
};
|
||||||
@@ -146,7 +146,7 @@ impl Localhost {
|
|||||||
// Update working directory
|
// Update working directory
|
||||||
self.wrkdir = new_dir;
|
self.wrkdir = new_dir;
|
||||||
// Scan new directory
|
// Scan new directory
|
||||||
self.files = match self.scan_dir() {
|
self.files = match self.scan_dir(self.wrkdir.as_path()) {
|
||||||
Ok(files) => files,
|
Ok(files) => files,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
// Restore directory
|
// Restore directory
|
||||||
@@ -170,7 +170,7 @@ impl Localhost {
|
|||||||
match std::fs::create_dir(dir_path) {
|
match std::fs::create_dir(dir_path) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
// Update dir
|
// Update dir
|
||||||
self.files = match self.scan_dir() {
|
self.files = match self.scan_dir(self.wrkdir.as_path()) {
|
||||||
Ok(f) => f,
|
Ok(f) => f,
|
||||||
Err(err) => return Err(err)
|
Err(err) => return Err(err)
|
||||||
};
|
};
|
||||||
@@ -196,7 +196,7 @@ impl Localhost {
|
|||||||
match std::fs::remove_dir_all(f_path) {
|
match std::fs::remove_dir_all(f_path) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
// Update dir
|
// Update dir
|
||||||
self.files = match self.scan_dir() {
|
self.files = match self.scan_dir(self.wrkdir.as_path()) {
|
||||||
Ok(f) => f,
|
Ok(f) => f,
|
||||||
Err(err) => return Err(err)
|
Err(err) => return Err(err)
|
||||||
};
|
};
|
||||||
@@ -215,7 +215,7 @@ impl Localhost {
|
|||||||
match std::fs::remove_file(f_path) {
|
match std::fs::remove_file(f_path) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
// Update dir
|
// Update dir
|
||||||
self.files = match self.scan_dir() {
|
self.files = match self.scan_dir(self.wrkdir.as_path()) {
|
||||||
Ok(f) => f,
|
Ok(f) => f,
|
||||||
Err(err) => return Err(err)
|
Err(err) => return Err(err)
|
||||||
};
|
};
|
||||||
@@ -238,7 +238,7 @@ impl Localhost {
|
|||||||
match std::fs::rename(abs_path.as_path(), dst_path) {
|
match std::fs::rename(abs_path.as_path(), dst_path) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
// Scan dir
|
// Scan dir
|
||||||
self.files = match self.scan_dir() {
|
self.files = match self.scan_dir(self.wrkdir.as_path()) {
|
||||||
Ok(f) => f,
|
Ok(f) => f,
|
||||||
Err(err) => return Err(err)
|
Err(err) => return Err(err)
|
||||||
};
|
};
|
||||||
@@ -285,8 +285,8 @@ impl Localhost {
|
|||||||
///
|
///
|
||||||
/// Get content of the current directory as a list of fs entry (Windows)
|
/// Get content of the current directory as a list of fs entry (Windows)
|
||||||
#[cfg(any(unix, macos, linux))]
|
#[cfg(any(unix, macos, linux))]
|
||||||
fn scan_dir(&self) -> Result<Vec<FsEntry>, HostError> {
|
pub fn scan_dir(&self, dir: &Path) -> Result<Vec<FsEntry>, HostError> {
|
||||||
let entries = match std::fs::read_dir(self.wrkdir.as_path()) {
|
let entries = match std::fs::read_dir(dir) {
|
||||||
Ok(e) => e,
|
Ok(e) => e,
|
||||||
Err(err) => return Err(HostError::new(HostErrorType::DirNotAccessible, Some(err))),
|
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)
|
/// Get content of the current directory as a list of fs entry (Windows)
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
#[cfg(not(tarpaulin_include))]
|
#[cfg(not(tarpaulin_include))]
|
||||||
fn scan_dir(&self) -> Result<Vec<FsEntry>, HostError> {
|
fn scan_dir(&self, dir: &Path) -> Result<Vec<FsEntry>, HostError> {
|
||||||
let entries = match std::fs::read_dir(self.wrkdir.as_path()) {
|
let entries = match std::fs::read_dir(dir) {
|
||||||
Ok(e) => e,
|
Ok(e) => e,
|
||||||
Err(err) => return Err(HostError::new(HostErrorType::DirNotAccessible, Some(err))),
|
Err(err) => return Err(HostError::new(HostErrorType::DirNotAccessible, Some(err))),
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user