cap_primitives/fs/via_parent/
access.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
use super::open_parent;
use crate::fs::{access_unchecked, AccessType, FollowSymlinks, MaybeOwnedFile};
use std::path::Path;
use std::{fs, io};

/// Implement `access` by `open`ing up the parent component of the path and
/// then calling `access_unchecked` on the last component.
pub(crate) fn access(
    start: &fs::File,
    path: &Path,
    type_: AccessType,
    follow: FollowSymlinks,
) -> io::Result<()> {
    let start = MaybeOwnedFile::borrowed(start);

    let (dir, basename) = open_parent(start, path)?;

    access_unchecked(&dir, basename.as_ref(), type_, follow)
}