mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-14 22:14:53 +00:00
Forward-port #9931
This commit is contained in:
parent
6ee81c0f15
commit
0cc1aef725
1 changed files with 7 additions and 4 deletions
|
@ -315,17 +315,20 @@ fn file_get_desc(
|
||||||
filename: &wstr,
|
filename: &wstr,
|
||||||
lstat: Option<fs::Metadata>,
|
lstat: Option<fs::Metadata>,
|
||||||
stat: Option<io::Result<fs::Metadata>>,
|
stat: Option<io::Result<fs::Metadata>>,
|
||||||
|
definitely_executable: bool,
|
||||||
) -> &'static wstr {
|
) -> &'static wstr {
|
||||||
let Some(lstat) = lstat else {
|
let Some(lstat) = lstat else {
|
||||||
return *COMPLETE_FILE_DESC;
|
return *COMPLETE_FILE_DESC;
|
||||||
};
|
};
|
||||||
|
|
||||||
fn is_executable(buf: &fs::Metadata, filename: &wstr) -> bool {
|
let is_executable = |buf: &fs::Metadata, filename: &wstr| -> bool {
|
||||||
// Weird group permissions and other such issues make it non-trivial to find out if
|
// Weird group permissions and other such issues make it non-trivial to find out if
|
||||||
// we can actually execute a file using the result from stat. It is much safer to
|
// we can actually execute a file using the result from stat. It is much safer to
|
||||||
// use the access function, since it tells us exactly what we want to know.
|
// use the access function, since it tells us exactly what we want to know.
|
||||||
(buf.mode() as mode_t & (S_IXUSR | S_IXGRP | S_IXOTH) != 0) && waccess(filename, X_OK) == 0
|
definitely_executable
|
||||||
}
|
|| (buf.mode() as mode_t & (S_IXUSR | S_IXGRP | S_IXOTH) != 0)
|
||||||
|
&& waccess(filename, X_OK) == 0
|
||||||
|
};
|
||||||
|
|
||||||
// stat was only queried if lstat succeeded
|
// stat was only queried if lstat succeeded
|
||||||
let stat = stat.unwrap();
|
let stat = stat.unwrap();
|
||||||
|
@ -444,7 +447,7 @@ fn wildcard_test_flags_then_complete(
|
||||||
|
|
||||||
// Compute the description.
|
// Compute the description.
|
||||||
let desc = if expand_flags.contains(ExpandFlags::GEN_DESCRIPTIONS) {
|
let desc = if expand_flags.contains(ExpandFlags::GEN_DESCRIPTIONS) {
|
||||||
let mut desc = file_get_desc(filename, lstat, stat).to_owned();
|
let mut desc = file_get_desc(filename, lstat, stat, executables_only).to_owned();
|
||||||
|
|
||||||
if !is_directory && !is_executable {
|
if !is_directory && !is_executable {
|
||||||
if !desc.is_empty() {
|
if !desc.is_empty() {
|
||||||
|
|
Loading…
Reference in a new issue