mirror of
https://github.com/nushell/nushell.git
synced 2024-11-25 01:43:47 +01:00
Fix deleting / showing ls
named pipes and other fs objects no… (#1461)
* Fix deleting named pipes * Use std::os::unix::fs::FileTypeExt to show correct type for unix-specific fs objects; Fix formatting Co-authored-by: Linards Kalvāns <linards.kalvans@twino.eu>
This commit is contained in:
parent
755d0e648b
commit
54bf671a50
@ -2,6 +2,35 @@ use crate::prelude::*;
|
||||
use nu_errors::ShellError;
|
||||
use nu_protocol::{TaggedDictBuilder, UntaggedValue, Value};
|
||||
|
||||
#[cfg(unix)]
|
||||
use std::os::unix::fs::FileTypeExt;
|
||||
|
||||
fn get_file_type(md: &std::fs::Metadata) -> &str {
|
||||
let ft = md.file_type();
|
||||
let mut file_type = "Unknown";
|
||||
if ft.is_dir() {
|
||||
file_type = "Dir";
|
||||
} else if ft.is_file() {
|
||||
file_type = "File";
|
||||
} else if ft.is_symlink() {
|
||||
file_type = "Symlink";
|
||||
} else {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
if ft.is_block_device() {
|
||||
file_type = "Block device";
|
||||
} else if ft.is_char_device() {
|
||||
file_type = "Char device";
|
||||
} else if ft.is_fifo() {
|
||||
file_type = "Pipe";
|
||||
} else if ft.is_socket() {
|
||||
file_type = "Socket";
|
||||
}
|
||||
}
|
||||
}
|
||||
file_type
|
||||
}
|
||||
|
||||
pub(crate) fn dir_entry_dict(
|
||||
filename: &std::path::Path,
|
||||
metadata: Option<&std::fs::Metadata>,
|
||||
@ -29,22 +58,16 @@ pub(crate) fn dir_entry_dict(
|
||||
dict.insert_untagged("name", UntaggedValue::string(name));
|
||||
|
||||
if let Some(md) = metadata {
|
||||
if md.is_dir() {
|
||||
dict.insert_untagged("type", UntaggedValue::string("Dir"));
|
||||
} else if md.is_file() {
|
||||
dict.insert_untagged("type", UntaggedValue::string("File"));
|
||||
} else {
|
||||
dict.insert_untagged("type", UntaggedValue::string("Symlink"));
|
||||
}
|
||||
dict.insert_untagged("type", get_file_type(md));
|
||||
} else {
|
||||
dict.insert_untagged("type", UntaggedValue::nothing());
|
||||
}
|
||||
|
||||
if full || with_symlink_targets {
|
||||
if let Some(md) = metadata {
|
||||
if md.is_dir() || md.is_file() {
|
||||
dict.insert_untagged("target", UntaggedValue::nothing());
|
||||
} else if let Ok(path_to_link) = filename.read_link() {
|
||||
let ft = md.file_type();
|
||||
if ft.is_symlink() {
|
||||
if let Ok(path_to_link) = filename.read_link() {
|
||||
dict.insert_untagged(
|
||||
"target",
|
||||
UntaggedValue::string(path_to_link.to_string_lossy()),
|
||||
@ -58,6 +81,9 @@ pub(crate) fn dir_entry_dict(
|
||||
} else {
|
||||
dict.insert_untagged("target", UntaggedValue::nothing());
|
||||
}
|
||||
} else {
|
||||
dict.insert_untagged("target", UntaggedValue::nothing());
|
||||
}
|
||||
}
|
||||
|
||||
if full {
|
||||
|
@ -978,7 +978,7 @@ impl Shell for FilesystemShell {
|
||||
};
|
||||
|
||||
let valid_target =
|
||||
f.is_file() || (f.is_dir() && (is_empty || recursive.item));
|
||||
f.exists() && (!f.is_dir() || (is_empty || recursive.item));
|
||||
if valid_target {
|
||||
if trash.item {
|
||||
match SendToTrash::remove(f) {
|
||||
|
Loading…
Reference in New Issue
Block a user