mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-28 20:55:11 +00:00
Use std::io::Error::last_os_error()
for errno
This commit is contained in:
parent
ca494778e4
commit
3dfc9082e6
1 changed files with 24 additions and 10 deletions
|
@ -1,6 +1,9 @@
|
||||||
//! Implementation of the realpath builtin.
|
//! Implementation of the realpath builtin.
|
||||||
|
|
||||||
|
use std::io::Error;
|
||||||
|
|
||||||
use libc::c_int;
|
use libc::c_int;
|
||||||
|
use nix::errno::errno;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ffi::parser_t,
|
ffi::parser_t,
|
||||||
|
@ -95,12 +98,22 @@ pub fn realpath(
|
||||||
if let Some(real_path) = wrealpath(arg) {
|
if let Some(real_path) = wrealpath(arg) {
|
||||||
streams.out.append(real_path);
|
streams.out.append(real_path);
|
||||||
} else {
|
} else {
|
||||||
// TODO: get error from errno
|
if errno() != 0 {
|
||||||
// Report the error and make it clear this is an error
|
// realpath() just couldn't do it. Report the error and make it clear
|
||||||
// from our builtin, not the system's realpath.
|
// this is an error from our builtin, not the system's realpath.
|
||||||
|
streams.err.append(wgettext_fmt!(
|
||||||
|
"builtin %ls: %ls: %s\n",
|
||||||
|
cmd,
|
||||||
|
arg,
|
||||||
|
Error::last_os_error().to_string()
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
// Who knows. Probably a bug in our wrealpath() implementation.
|
||||||
streams
|
streams
|
||||||
.err
|
.err
|
||||||
.append(wgettext_fmt!("builtin %ls: %ls\n", cmd, arg));
|
.append(wgettext_fmt!("builtin %ls: Invalid arg: %ls\n", cmd, arg));
|
||||||
|
}
|
||||||
|
|
||||||
return STATUS_CMD_ERROR;
|
return STATUS_CMD_ERROR;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -115,10 +128,11 @@ pub fn realpath(
|
||||||
};
|
};
|
||||||
streams.out.append(normalize_path(&absolute_arg, false));
|
streams.out.append(normalize_path(&absolute_arg, false));
|
||||||
} else {
|
} else {
|
||||||
// TODO: get error from errno
|
streams.err.append(wgettext_fmt!(
|
||||||
streams
|
"builtin %ls: realpath failed: %s\n",
|
||||||
.err
|
cmd,
|
||||||
.append(wgettext_fmt!("builtin %ls: realpath failed\n", cmd));
|
std::io::Error::last_os_error().to_string()
|
||||||
|
));
|
||||||
return STATUS_CMD_ERROR;
|
return STATUS_CMD_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue