mirror of
https://github.com/uutils/coreutils
synced 2024-09-16 06:21:12 +00:00
ls: device number for BSDs and solarishOS (#4841)
This commit is contained in:
parent
d8f1f1c16c
commit
452be5a220
|
@ -41,7 +41,13 @@ use unicode_width::UnicodeWidthStr;
|
|||
target_os = "linux",
|
||||
target_os = "macos",
|
||||
target_os = "android",
|
||||
target_os = "ios"
|
||||
target_os = "ios",
|
||||
target_os = "freebsd",
|
||||
target_os = "dragonfly",
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd",
|
||||
target_os = "illumos",
|
||||
target_os = "solaris"
|
||||
))]
|
||||
use uucore::libc::{dev_t, major, minor};
|
||||
#[cfg(unix)]
|
||||
|
@ -2716,7 +2722,13 @@ fn display_len_or_rdev(metadata: &Metadata, config: &Config) -> SizeOrDeviceId {
|
|||
target_os = "linux",
|
||||
target_os = "macos",
|
||||
target_os = "android",
|
||||
target_os = "ios"
|
||||
target_os = "ios",
|
||||
target_os = "freebsd",
|
||||
target_os = "dragonfly",
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd",
|
||||
target_os = "illumos",
|
||||
target_os = "solaris"
|
||||
))]
|
||||
{
|
||||
let ft = metadata.file_type();
|
||||
|
|
|
@ -3393,3 +3393,44 @@ fn test_tabsize_formatting() {
|
|||
.succeeds()
|
||||
.stdout_is("aaaaaaaa bbbb\ncccc dddddddd");
|
||||
}
|
||||
|
||||
#[cfg(any(
|
||||
target_os = "linux",
|
||||
target_os = "macos",
|
||||
target_os = "ios",
|
||||
target_os = "freebsd",
|
||||
target_os = "dragonfly",
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd",
|
||||
target_os = "illumos",
|
||||
target_os = "solaris"
|
||||
))]
|
||||
#[test]
|
||||
fn test_device_number() {
|
||||
use std::fs::{metadata, read_dir};
|
||||
use std::os::unix::fs::{FileTypeExt, MetadataExt};
|
||||
use uucore::libc::{dev_t, major, minor};
|
||||
|
||||
let dev_dir = read_dir("/dev").unwrap();
|
||||
// let's use the first device for test
|
||||
let blk_dev = dev_dir
|
||||
.map(|res_entry| res_entry.unwrap())
|
||||
.find(|entry| {
|
||||
entry.file_type().unwrap().is_block_device()
|
||||
|| entry.file_type().unwrap().is_char_device()
|
||||
})
|
||||
.expect("Expect a block/char device");
|
||||
let blk_dev_path = blk_dev.path();
|
||||
let blk_dev_meta = metadata(blk_dev_path.as_path()).unwrap();
|
||||
let blk_dev_number = blk_dev_meta.rdev() as dev_t;
|
||||
let (major, minor) = unsafe { (major(blk_dev_number), minor(blk_dev_number)) };
|
||||
let major_minor_str = format!("{}, {}", major, minor);
|
||||
|
||||
let scene = TestScenario::new(util_name!());
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("-l")
|
||||
.arg(blk_dev_path.to_str().expect("should be UTF-8 encoded"))
|
||||
.succeeds()
|
||||
.stdout_contains(major_minor_str);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue