Skip to content

Commit

Permalink
Merge pull request #4014 from tertsdiepraam/ls-windows-permissions
Browse files Browse the repository at this point in the history
`ls`, `stat`: Show more info in long format on Windows
  • Loading branch information
sylvestre authored Oct 22, 2022
2 parents 5f9e66a + 538e8ec commit e4fe2b1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
20 changes: 17 additions & 3 deletions src/uucore/src/lib/features/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,12 +402,26 @@ pub fn canonicalize<P: AsRef<Path>>(
}

#[cfg(not(unix))]
#[allow(unused_variables)]
pub fn display_permissions(metadata: &fs::Metadata, display_file_type: bool) -> String {
let write = if metadata.permissions().readonly() {
'-'
} else {
'w'
};

if display_file_type {
return String::from("----------");
let file_type = if metadata.is_symlink() {
'l'
} else if metadata.is_dir() {
'd'
} else {
'-'
};

format!("{0}r{1}xr{1}xr{1}x", file_type, write)
} else {
format!("r{0}xr{0}xr{0}x", write)
}
String::from("---------")
}

#[cfg(unix)]
Expand Down
2 changes: 1 addition & 1 deletion tests/by-util/test_ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ fn test_ls_long() {
result.stdout_matches(&Regex::new(r"[-bcCdDlMnpPsStTx?]([r-][w-][xt-]){3}.*").unwrap());

#[cfg(windows)]
result.stdout_contains("---------- 1 somebody somegroup");
result.stdout_matches(&Regex::new(r"[-dl](r[w-]x){3}.*").unwrap());
}
}

Expand Down

0 comments on commit e4fe2b1

Please sign in to comment.