mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 21:33:09 +00:00
cleanup: fds::open_dir - remove mode argument
[w]open_dir does not pass O_CREAT, so the mode argument to open is never used. also, O_CREAT | O_DIRECTORY could not be used (portably) to create a directory. (on POSIX does not specify what should happen, on Linux it is EINVAL.)
This commit is contained in:
parent
e32efc0581
commit
2ecbdb9ae7
3 changed files with 6 additions and 7 deletions
|
@ -9,7 +9,6 @@ use crate::{
|
|||
};
|
||||
use errno::Errno;
|
||||
use libc::{fchdir, EACCES, ELOOP, ENOENT, ENOTDIR, EPERM};
|
||||
use nix::sys::stat::Mode;
|
||||
use std::{os::fd::AsRawFd, sync::Arc};
|
||||
|
||||
// The cd builtin. Changes the current directory to the one specified or to $HOME if none is
|
||||
|
@ -87,7 +86,7 @@ pub fn cd(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Optio
|
|||
|
||||
errno::set_errno(Errno(0));
|
||||
|
||||
let res = wopen_dir(&norm_dir, Mode::empty()).map_err(|err| err as i32);
|
||||
let res = wopen_dir(&norm_dir).map_err(|err| err as i32);
|
||||
|
||||
let res = res.and_then(|fd| {
|
||||
if unsafe { fchdir(fd.as_raw_fd()) } == 0 {
|
||||
|
|
|
@ -261,13 +261,13 @@ pub fn open_cloexec(path: &CStr, flags: OFlag, mode: nix::sys::stat::Mode) -> ni
|
|||
|
||||
/// Wide character version of open_dir() that also sets the close-on-exec flag (atomically when
|
||||
/// possible).
|
||||
pub fn wopen_dir(pathname: &wstr, mode: nix::sys::stat::Mode) -> nix::Result<OwnedFd> {
|
||||
open_dir(wcs2zstring(pathname).as_c_str(), mode)
|
||||
pub fn wopen_dir(pathname: &wstr) -> nix::Result<OwnedFd> {
|
||||
open_dir(wcs2zstring(pathname).as_c_str())
|
||||
}
|
||||
|
||||
/// Narrow version of wopen_dir().
|
||||
pub fn open_dir(path: &CStr, mode: nix::sys::stat::Mode) -> nix::Result<OwnedFd> {
|
||||
open_cloexec(path, OFlag::O_RDONLY | OFlag::O_DIRECTORY, mode).map(OwnedFd::from)
|
||||
pub fn open_dir(path: &CStr) -> nix::Result<OwnedFd> {
|
||||
open_cloexec(path, OFlag::O_RDONLY | OFlag::O_DIRECTORY, nix::sys::stat::Mode::empty()).map(OwnedFd::from)
|
||||
}
|
||||
|
||||
/// Close a file descriptor `fd`, retrying on EINTR.
|
||||
|
|
|
@ -352,7 +352,7 @@ impl Parser {
|
|||
global_event_blocks: AtomicU64::new(0),
|
||||
});
|
||||
|
||||
match open_dir(CStr::from_bytes_with_nul(b".\0").unwrap(), Mode::empty()) {
|
||||
match open_dir(CStr::from_bytes_with_nul(b".\0").unwrap()) {
|
||||
Ok(fd) => {
|
||||
result.libdata_mut().cwd_fd = Some(Arc::new(fd));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue