Sha256: 898a5345b27e6b084d040888579e166b1a927e8079f2845cc879072dbdeca7dc

Contents?: true

Size: 1.03 KB

Versions: 19

Compression:

Stored size: 1.03 KB

Contents

use crate::fs::{errors, is_root_dir, read_dir_unchecked, FollowSymlinks, Metadata};
use std::path::Component;
use std::{fs, io};

/// Delete the directory referenced by the given handle by searching for it in
/// its `..`. This requires search permission in `..`, but that's usually
/// available.
pub(crate) fn remove_open_dir_by_searching(dir: fs::File) -> io::Result<()> {
    let metadata = Metadata::from_file(&dir)?;
    let mut iter = read_dir_unchecked(&dir, Component::ParentDir.as_ref(), FollowSymlinks::No)?;
    while let Some(child) = iter.next() {
        let child = child?;
        if child.is_same_file(&metadata)? {
            return child.remove_dir();
        }
    }

    // We didn't find the directory among its parent's children. Check for the
    // root directory and handle it specially -- removal will probably fail, so
    // we'll get the appropriate error code.
    if is_root_dir(&dir, &iter)? {
        fs::remove_dir(Component::RootDir.as_os_str())
    } else {
        Err(errors::no_such_file_or_directory())
    }
}

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
wasmtime-14.0.4 ./ext/cargo-vendor/cap-primitives-2.0.0/src/rustix/fs/remove_open_dir_by_searching.rs
wasmtime-14.0.3 ./ext/cargo-vendor/cap-primitives-2.0.0/src/rustix/fs/remove_open_dir_by_searching.rs
wasmtime-14.0.1 ./ext/cargo-vendor/cap-primitives-2.0.0/src/rustix/fs/remove_open_dir_by_searching.rs
wasmtime-14.0.0 ./ext/cargo-vendor/cap-primitives-2.0.0/src/rustix/fs/remove_open_dir_by_searching.rs
wasmtime-13.0.0 ./ext/cargo-vendor/cap-primitives-2.0.0/src/rustix/fs/remove_open_dir_by_searching.rs
wasmtime-12.0.1 ./ext/cargo-vendor/cap-primitives-2.0.0/src/rustix/fs/remove_open_dir_by_searching.rs
wasmtime-12.0.0 ./ext/cargo-vendor/cap-primitives-2.0.0/src/rustix/fs/remove_open_dir_by_searching.rs
wasmtime-11.0.0 ./ext/cargo-vendor/cap-primitives-1.0.15/src/rustix/fs/remove_open_dir_by_searching.rs
wasmtime-10.0.1 ./ext/cargo-vendor/cap-primitives-1.0.15/src/rustix/fs/remove_open_dir_by_searching.rs
wasmtime-10.0.0 ./ext/cargo-vendor/cap-primitives-1.0.15/src/rustix/fs/remove_open_dir_by_searching.rs
wasmtime-9.0.4 ./ext/cargo-vendor/cap-primitives-1.0.15/src/rustix/fs/remove_open_dir_by_searching.rs
wasmtime-9.0.1 ./ext/cargo-vendor/cap-primitives-1.0.15/src/rustix/fs/remove_open_dir_by_searching.rs
wasmtime-8.0.0 ./ext/cargo-vendor/cap-primitives-1.0.14/src/rustix/fs/remove_open_dir_by_searching.rs
wasmtime-7.0.0 ./ext/cargo-vendor/cap-primitives-1.0.9/src/rustix/fs/remove_open_dir_by_searching.rs
wasmtime-6.0.1 ./ext/cargo-vendor/cap-primitives-1.0.5/src/rustix/fs/remove_open_dir_by_searching.rs
wasmtime-6.0.0 ./ext/cargo-vendor/cap-primitives-1.0.5/src/rustix/fs/remove_open_dir_by_searching.rs
wasmtime-5.0.0 ./ext/cargo-vendor/cap-primitives-1.0.4/src/rustix/fs/remove_open_dir_by_searching.rs
wasmtime-0.4.1 ./ext/cargo-vendor/cap-primitives-1.0.3/src/rustix/fs/remove_open_dir_by_searching.rs
wasmtime-0.4.0 ./ext/cargo-vendor/cap-primitives-1.0.2/src/rustix/fs/remove_open_dir_by_searching.rs