mirror of
https://github.com/nushell/nushell.git
synced 2024-11-28 19:33: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_errors::ShellError;
|
||||||
use nu_protocol::{TaggedDictBuilder, UntaggedValue, Value};
|
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(
|
pub(crate) fn dir_entry_dict(
|
||||||
filename: &std::path::Path,
|
filename: &std::path::Path,
|
||||||
metadata: Option<&std::fs::Metadata>,
|
metadata: Option<&std::fs::Metadata>,
|
||||||
@ -29,22 +58,16 @@ pub(crate) fn dir_entry_dict(
|
|||||||
dict.insert_untagged("name", UntaggedValue::string(name));
|
dict.insert_untagged("name", UntaggedValue::string(name));
|
||||||
|
|
||||||
if let Some(md) = metadata {
|
if let Some(md) = metadata {
|
||||||
if md.is_dir() {
|
dict.insert_untagged("type", get_file_type(md));
|
||||||
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"));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
dict.insert_untagged("type", UntaggedValue::nothing());
|
dict.insert_untagged("type", UntaggedValue::nothing());
|
||||||
}
|
}
|
||||||
|
|
||||||
if full || with_symlink_targets {
|
if full || with_symlink_targets {
|
||||||
if let Some(md) = metadata {
|
if let Some(md) = metadata {
|
||||||
if md.is_dir() || md.is_file() {
|
let ft = md.file_type();
|
||||||
dict.insert_untagged("target", UntaggedValue::nothing());
|
if ft.is_symlink() {
|
||||||
} else if let Ok(path_to_link) = filename.read_link() {
|
if let Ok(path_to_link) = filename.read_link() {
|
||||||
dict.insert_untagged(
|
dict.insert_untagged(
|
||||||
"target",
|
"target",
|
||||||
UntaggedValue::string(path_to_link.to_string_lossy()),
|
UntaggedValue::string(path_to_link.to_string_lossy()),
|
||||||
@ -58,6 +81,9 @@ pub(crate) fn dir_entry_dict(
|
|||||||
} else {
|
} else {
|
||||||
dict.insert_untagged("target", UntaggedValue::nothing());
|
dict.insert_untagged("target", UntaggedValue::nothing());
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
dict.insert_untagged("target", UntaggedValue::nothing());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if full {
|
if full {
|
||||||
|
@ -978,7 +978,7 @@ impl Shell for FilesystemShell {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let valid_target =
|
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 valid_target {
|
||||||
if trash.item {
|
if trash.item {
|
||||||
match SendToTrash::remove(f) {
|
match SendToTrash::remove(f) {
|
||||||
|
Loading…
Reference in New Issue
Block a user