cap_primitives/fs/via_parent/
create_dir.rs

1use super::open_parent;
2use crate::fs::{create_dir_unchecked, strip_dir_suffix, DirOptions, MaybeOwnedFile};
3use std::path::Path;
4use std::{fs, io};
5
6/// Implement `create_dir` by `open`ing up the parent component of the path and
7/// then calling `create_dir_unchecked` on the last component.
8pub(crate) fn create_dir(start: &fs::File, path: &Path, options: &DirOptions) -> io::Result<()> {
9    let start = MaybeOwnedFile::borrowed(start);
10
11    // As a special case, `create_dir` ignores a trailing slash rather than
12    // treating it as equivalent to a trailing slash-dot, so strip any trailing
13    // slashes.
14    let path = strip_dir_suffix(path);
15
16    let (dir, basename) = open_parent(start, &path)?;
17
18    create_dir_unchecked(&dir, basename.as_ref(), options)
19}