From b076e375cab7e9f822e5c717341956f1e792b00d Mon Sep 17 00:00:00 2001 From: Luccas Mateus Date: Fri, 2 Oct 2020 01:50:55 -0300 Subject: [PATCH] Fix broken removal of sockets (#2629) * make sort-by fail gracefully if mismatched types are compared * Added a test to check if sorted-by with invalid types exists gracefully * Linter changes * removed redundant pattern matching * Changed the error message * Added a comma after every argument * Changed the test to accomodate the new err messages * Err message for sort-by invalid types now shows the mismatched types * Lints problems * Changed unwrap to expect * Added the -f flag to rm command Now when you a use rm -f there will be no error message, even if the file doesnt actually exist * Lint problems * Fixed the wrong line * Removed println * Spelling mistake * Fix problems when you mv a file into itself * Lint mistakes * Remove unecessary filtering in most cases * Allow the removal of sockets * Conditional compilations to systems without socket --- crates/nu-cli/src/shell/filesystem_shell.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/nu-cli/src/shell/filesystem_shell.rs b/crates/nu-cli/src/shell/filesystem_shell.rs index 76cb0ac230..c9d18f6e1f 100644 --- a/crates/nu-cli/src/shell/filesystem_shell.rs +++ b/crates/nu-cli/src/shell/filesystem_shell.rs @@ -596,9 +596,15 @@ impl Shell for FilesystemShell { }; if let Ok(metadata) = f.symlink_metadata() { + #[cfg(unix)] + let is_socket = metadata.file_type().is_socket(); + #[cfg(not(unix))] + let is_socket = false; + if metadata.is_file() || metadata.file_type().is_symlink() || recursive.item + || is_socket || is_empty() { let result; @@ -620,7 +626,7 @@ impl Shell for FilesystemShell { } #[cfg(not(feature = "trash-support"))] { - result = if metadata.is_file() { + result = if metadata.is_file() || is_socket { std::fs::remove_file(&f) } else { std::fs::remove_dir_all(&f)