1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 11:07:44 +00:00

ls: On Windows use DirEntry#metadata() instead of fs::metadata

This commit is contained in:
moko256 2022-01-09 08:36:01 +09:00
parent 63ef039b4f
commit 5659bf8fae
No known key found for this signature in database
GPG key ID: A41D2A7C9077A570
2 changed files with 36 additions and 2 deletions

View file

@ -1412,8 +1412,7 @@ fn sort_entries(entries: &mut Vec<PathData>, config: &Config) {
fn is_hidden(file_path: &DirEntry) -> bool { fn is_hidden(file_path: &DirEntry) -> bool {
#[cfg(windows)] #[cfg(windows)]
{ {
let path = file_path.path(); let metadata = file_path.metadata().unwrap();
let metadata = fs::metadata(&path).unwrap_or_else(|_| fs::symlink_metadata(&path).unwrap());
let attr = metadata.file_attributes(); let attr = metadata.file_attributes();
(attr & 0x2) > 0 (attr & 0x2) > 0
} }

View file

@ -1642,6 +1642,41 @@ fn test_ls_hidden_windows() {
scene.ucmd().arg("-a").succeeds().stdout_contains(file); scene.ucmd().arg("-a").succeeds().stdout_contains(file);
} }
#[cfg(windows)]
#[test]
fn test_ls_hidden_link_windows() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let file = "visibleWindowsFileNoDot";
at.touch(file);
let link = "hiddenWindowsLinkNoDot";
at.symlink_dir(file, link);
// hide the link
scene.cmd("attrib").arg("/l").arg("+h").arg(link).succeeds();
scene
.ucmd()
.succeeds()
.stdout_contains(file)
.stdout_does_not_contain(link);
scene
.ucmd()
.arg("-a")
.succeeds()
.stdout_contains(file)
.stdout_contains(link);
}
#[cfg(windows)]
#[test]
fn test_ls_success_on_c_drv_root_windows() {
let scene = TestScenario::new(util_name!());
scene.ucmd().arg("C:\\").succeeds();
}
#[test] #[test]
fn test_ls_version_sort() { fn test_ls_version_sort() {
let scene = TestScenario::new(util_name!()); let scene = TestScenario::new(util_name!());