Function cap_primitives::fs::open_dir

source ·
pub fn open_dir(start: &File, path: &Path) -> Result<File>
Expand description

Open a directory by performing an openat-like operation, ensuring that the resolution of the path never escapes the directory tree rooted at start.

Examples found in repository?
src/windows/fs/read_dir_inner.rs (line 17)
11
12
13
14
15
16
17
18
19
    pub(crate) fn new(start: &fs::File, path: &Path, follow: FollowSymlinks) -> io::Result<Self> {
        assert_eq!(
            follow,
            FollowSymlinks::Yes,
            "`read_dir` without following symlinks is not implemented yet"
        );
        let dir = open_dir(start, path)?;
        Self::new_unchecked(&dir, Component::CurDir.as_ref())
    }
More examples
Hide additional examples
src/fs/via_parent/open_parent.rs (line 24)
15
16
17
18
19
20
21
22
23
24
25
26
27
28
pub(super) fn open_parent<'path, 'borrow>(
    start: MaybeOwnedFile<'borrow>,
    path: &'path Path,
) -> io::Result<(MaybeOwnedFile<'borrow>, &'path OsStr)> {
    let (dirname, basename) = split_parent(path).ok_or_else(errors::no_such_file_or_directory)?;

    let dir = if dirname.as_os_str().is_empty() {
        start
    } else {
        MaybeOwnedFile::owned(open_dir(&start, dirname)?)
    };

    Ok((dir, basename.as_os_str()))
}
src/windows/fs/remove_dir_all_impl.rs (line 8)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
pub(crate) fn remove_dir_all_impl(start: &fs::File, path: &Path) -> io::Result<()> {
    // Open the directory, following symlinks, to make sure it is a directory.
    let file = open_dir(start, path)?;
    // Test whether the path is a symlink.
    let md = stat(start, path, FollowSymlinks::No)?;
    drop(file);
    if md.is_symlink() {
        // If so, just remove the link.
        remove_dir(start, path)
    } else {
        // Otherwise, remove the tree.
        let dir = open_dir_nofollow(start, path)?;
        remove_open_dir_all_impl(dir)
    }
}