mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
Fixed remove
This commit is contained in:
@@ -201,18 +201,16 @@ impl Localhost {
|
|||||||
|
|
||||||
/// ### remove
|
/// ### remove
|
||||||
///
|
///
|
||||||
/// Remove file entry from current directory
|
/// Remove file entry
|
||||||
pub fn remove(&mut self, entry: &FsEntry) -> Result<(), HostError> {
|
pub fn remove(&mut self, entry: &FsEntry) -> Result<(), HostError> {
|
||||||
let mut f_path: PathBuf = self.wrkdir.clone();
|
|
||||||
match entry {
|
match entry {
|
||||||
FsEntry::Directory(dir) => {
|
FsEntry::Directory(dir) => {
|
||||||
f_path.push(dir.name.clone());
|
|
||||||
// If file doesn't exist; return error
|
// If file doesn't exist; return error
|
||||||
if ! f_path.exists() {
|
if ! dir.abs_path.as_path().exists() {
|
||||||
return Err(HostError::new(HostErrorType::NoSuchFileOrDirectory, None))
|
return Err(HostError::new(HostErrorType::NoSuchFileOrDirectory, None))
|
||||||
}
|
}
|
||||||
// Remove
|
// Remove
|
||||||
match std::fs::remove_dir_all(f_path) {
|
match std::fs::remove_dir_all(dir.abs_path.as_path()) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
// Update dir
|
// Update dir
|
||||||
self.files = match self.scan_dir(self.wrkdir.as_path()) {
|
self.files = match self.scan_dir(self.wrkdir.as_path()) {
|
||||||
@@ -225,13 +223,12 @@ impl Localhost {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
FsEntry::File(file) => {
|
FsEntry::File(file) => {
|
||||||
f_path.push(file.name.clone());
|
|
||||||
// If file doesn't exist; return error
|
// If file doesn't exist; return error
|
||||||
if ! f_path.exists() {
|
if ! file.abs_path.as_path().exists() {
|
||||||
return Err(HostError::new(HostErrorType::NoSuchFileOrDirectory, None))
|
return Err(HostError::new(HostErrorType::NoSuchFileOrDirectory, None))
|
||||||
}
|
}
|
||||||
// Remove
|
// Remove
|
||||||
match std::fs::remove_file(f_path) {
|
match std::fs::remove_file(file.abs_path.as_path()) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
// Update dir
|
// Update dir
|
||||||
self.files = match self.scan_dir(self.wrkdir.as_path()) {
|
self.files = match self.scan_dir(self.wrkdir.as_path()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user