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