Skip to content

Commit ea2cde6

Browse files
committed
Rename cap-primitives' mkdir to create_dir.
1 parent 69a3cf4 commit ea2cde6

File tree

14 files changed

+56
-56
lines changed

14 files changed

+56
-56
lines changed

cap-async-std/src/fs/dir.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use async_std::os::wasi::{
66
};
77
use async_std::{fs, io};
88
use cap_primitives::fs::{
9-
canonicalize, copy, hard_link, mkdir, open, open_ambient_dir, open_dir, read_dir, readlink,
10-
remove_dir_all, remove_open_dir, remove_open_dir_all, rename, rmdir, set_permissions, stat,
11-
unlink, DirOptions, FollowSymlinks, Permissions,
9+
canonicalize, copy, create_dir, hard_link, open, open_ambient_dir, open_dir, read_dir,
10+
readlink, remove_dir_all, remove_open_dir, remove_open_dir_all, rename, rmdir, set_permissions,
11+
stat, unlink, DirOptions, FollowSymlinks, Permissions,
1212
};
1313
use std::{
1414
fmt,
@@ -144,7 +144,7 @@ impl Dir {
144144

145145
fn _create_dir_one(&self, path: &Path, dir_options: &DirOptions) -> io::Result<()> {
146146
let file = unsafe { as_sync(&self.std_file) };
147-
mkdir(&file, path, dir_options)
147+
create_dir(&file, path, dir_options)
148148
}
149149

150150
fn _create_dir_all(&self, path: &Path, dir_options: &DirOptions) -> io::Result<()> {

cap-primitives/src/fs/mkdir.rs renamed to cap-primitives/src/fs/create_dir.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
//! This defines `mkdir`, the primary entrypoint to sandboxed directory creation.
1+
//! This defines `create_dir`, the primary entrypoint to sandboxed directory creation.
22
33
#[cfg(racy_asserts)]
44
use crate::fs::{
5-
canonicalize, map_result, mkdir_unchecked, stat_unchecked, FollowSymlinks, Metadata,
5+
canonicalize, create_dir_unchecked, map_result, stat_unchecked, FollowSymlinks, Metadata,
66
};
7-
use crate::fs::{mkdir_impl, DirOptions};
7+
use crate::fs::{create_dir_impl, DirOptions};
88
use std::{fs, io, path::Path};
99

1010
/// Perform a `mkdirat`-like operation, ensuring that the resolution of the path
1111
/// never escapes the directory tree rooted at `start`.
1212
#[cfg_attr(not(racy_asserts), allow(clippy::let_and_return))]
1313
#[inline]
14-
pub fn mkdir(start: &fs::File, path: &Path, options: &DirOptions) -> io::Result<()> {
14+
pub fn create_dir(start: &fs::File, path: &Path, options: &DirOptions) -> io::Result<()> {
1515
#[cfg(racy_asserts)]
1616
let stat_before = stat_unchecked(start, path, FollowSymlinks::No);
1717

1818
// Call the underlying implementation.
19-
let result = mkdir_impl(start, path, options);
19+
let result = create_dir_impl(start, path, options);
2020

2121
#[cfg(racy_asserts)]
2222
let stat_after = stat_unchecked(start, path, FollowSymlinks::No);
2323

2424
#[cfg(racy_asserts)]
25-
check_mkdir(start, path, options, &stat_before, &result, &stat_after);
25+
check_create_dir(start, path, options, &stat_before, &result, &stat_after);
2626

2727
result
2828
}
2929

3030
#[cfg(racy_asserts)]
3131
#[allow(clippy::enum_glob_use)]
32-
fn check_mkdir(
32+
fn check_create_dir(
3333
start: &fs::File,
3434
path: &Path,
3535
options: &DirOptions,
@@ -62,12 +62,12 @@ fn check_mkdir(
6262
}
6363

6464
(_, Err((kind, message)), _) => match map_result(&canonicalize(start, path)) {
65-
Ok(canon) => match map_result(&mkdir_unchecked(start, &canon, options)) {
65+
Ok(canon) => match map_result(&create_dir_unchecked(start, &canon, options)) {
6666
Err((unchecked_kind, unchecked_message)) => {
6767
assert_eq!(
6868
kind,
6969
unchecked_kind,
70-
"unexpected error kind from mkdir start='{:?}', \
70+
"unexpected error kind from create_dir start='{:?}', \
7171
path='{}':\nstat_before={:#?}\nresult={:#?}\nstat_after={:#?}",
7272
start,
7373
path.display(),
@@ -77,7 +77,7 @@ fn check_mkdir(
7777
);
7878
assert_eq!(message, unchecked_message);
7979
}
80-
_ => panic!("unsandboxed mkdir success"),
80+
_ => panic!("unsandboxed create_dir success"),
8181
},
8282
Err((_canon_kind, _canon_message)) => {
8383
/* TODO: Check error messages
@@ -88,7 +88,7 @@ fn check_mkdir(
8888
},
8989

9090
other => panic!(
91-
"inconsistent mkdir checks: start='{:?}' path='{}':\n{:#?}",
91+
"inconsistent create_dir checks: start='{:?}' path='{}':\n{:#?}",
9292
start,
9393
path.display(),
9494
other,

cap-primitives/src/fs/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub(crate) mod assert_same_file;
66

77
mod canonicalize;
88
mod copy;
9+
mod create_dir;
910
mod dir_builder;
1011
mod dir_entry;
1112
mod dir_options;
@@ -18,7 +19,6 @@ mod hard_link;
1819
mod is_read_write;
1920
mod maybe_owned_file;
2021
mod metadata;
21-
mod mkdir;
2222
mod open;
2323
mod open_dir;
2424
mod open_options;
@@ -55,6 +55,7 @@ pub(crate) use super::winx::fs::*;
5555

5656
pub use canonicalize::*;
5757
pub use copy::*;
58+
pub use create_dir::*;
5859
pub use dir_builder::*;
5960
pub use dir_entry::*;
6061
pub use dir_options::*;
@@ -63,7 +64,6 @@ pub use follow_symlinks::*;
6364
pub use hard_link::*;
6465
pub use is_read_write::is_read_write;
6566
pub use metadata::*;
66-
pub use mkdir::*;
6767
pub use open::*;
6868
pub use open_dir::*;
6969
pub use open_options::*;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use super::open_parent;
2+
use crate::fs::{create_dir_unchecked, strip_dir_suffix, DirOptions, MaybeOwnedFile};
3+
use std::{fs, io, path::Path};
4+
5+
/// Implement `create_dir` by `open`ing up the parent component of the path and
6+
/// then calling `create_dir_unchecked` on the last component.
7+
pub(crate) fn create_dir(start: &fs::File, path: &Path, options: &DirOptions) -> io::Result<()> {
8+
let start = MaybeOwnedFile::borrowed(start);
9+
10+
// As a special case, `create_dir` ignores a trailing slash rather than treating
11+
// it as equivalent to a trailing slash-dot, so strip any trailing slashes.
12+
let path = strip_dir_suffix(path);
13+
14+
let (dir, basename) = open_parent(start, &path)?;
15+
16+
create_dir_unchecked(&dir, basename.as_ref(), options)
17+
}

cap-primitives/src/fs/via_parent/mkdir.rs

Lines changed: 0 additions & 17 deletions
This file was deleted.

cap-primitives/src/fs/via_parent/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//! In many operations, the last component of a path is special. For example,
2-
//! in `mkdir`, the last component names the path to be created, while the
2+
//! in `create_dir`, the last component names the path to be created, while the
33
//! rest of the components just name the place to create it in.
44
5+
mod create_dir;
56
mod hard_link;
6-
mod mkdir;
77
mod open_parent;
88
#[cfg(not(windows))] // doesn't work on windows; use a windows-specific impl
99
mod readlink;
@@ -18,8 +18,8 @@ mod unlink;
1818

1919
use open_parent::open_parent;
2020

21+
pub(crate) use create_dir::create_dir;
2122
pub(crate) use hard_link::hard_link;
22-
pub(crate) use mkdir::mkdir;
2323
#[cfg(not(windows))] // doesn't work on windows; use a windows-specific impl
2424
pub(crate) use readlink::readlink;
2525
pub(crate) use rename::rename;

cap-primitives/src/posish/fs/mkdir_unchecked.rs renamed to cap-primitives/src/posish/fs/create_dir_unchecked.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use crate::fs::DirOptions;
22
use posish::fs::{mkdirat, Mode};
33
use std::{fs, io, path::Path};
44

5-
/// *Unsandboxed* function similar to `mkdir`, but which does not perform sandboxing.
6-
pub(crate) fn mkdir_unchecked(
5+
/// *Unsandboxed* function similar to `create_dir`, but which does not perform sandboxing.
6+
pub(crate) fn create_dir_unchecked(
77
start: &fs::File,
88
path: &Path,
99
options: &DirOptions,

cap-primitives/src/posish/fs/dir_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ pub(crate) fn append_dir_suffix(path: PathBuf) -> PathBuf {
5252
}
5353

5454
/// Strip trailing `/`s, unless this reduces `path` to `/` itself. This is
55-
/// used by `mkdir` and others to prevent paths like `foo/` from canonicalizing
56-
/// to `foo/.` since these syscalls treat these differently.
55+
/// used by `create_dir` and others to prevent paths like `foo/` from
56+
/// canonicalizing to `foo/.` since these syscalls treat these differently.
5757
#[allow(clippy::indexing_slicing)]
5858
pub(crate) fn strip_dir_suffix(path: &Path) -> impl Deref<Target = Path> + '_ {
5959
let mut bytes = path.as_os_str().as_bytes();

cap-primitives/src/posish/fs/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
mod c_str;
22
mod copy;
3+
mod create_dir_unchecked;
34
mod dir_entry_inner;
45
mod dir_options_ext;
56
mod dir_utils;
@@ -10,7 +11,6 @@ mod is_root_dir;
1011
#[cfg(racy_asserts)]
1112
mod is_same_file;
1213
mod metadata_ext;
13-
mod mkdir_unchecked;
1414
mod oflags;
1515
mod open_options_ext;
1616
mod open_unchecked;
@@ -63,7 +63,7 @@ pub(crate) use {set_permissions_impl::set_permissions_impl, set_times_impl::set_
6363
#[rustfmt::skip]
6464
pub(crate) use crate::fs::{
6565
via_parent::hard_link as hard_link_impl,
66-
via_parent::mkdir as mkdir_impl,
66+
via_parent::create_dir as create_dir_impl,
6767
via_parent::readlink as readlink_impl,
6868
via_parent::rename as rename_impl,
6969
via_parent::rmdir as rmdir_impl,
@@ -75,6 +75,7 @@ pub(crate) use crate::fs::{
7575
#[allow(unused_imports)]
7676
pub(crate) use c_str::c_str;
7777
pub(crate) use copy::*;
78+
pub(crate) use create_dir_unchecked::*;
7879
pub(crate) use dir_entry_inner::*;
7980
pub(crate) use dir_options_ext::*;
8081
pub(crate) use dir_utils::*;
@@ -85,7 +86,6 @@ pub(crate) use is_root_dir::*;
8586
#[cfg(racy_asserts)]
8687
pub(crate) use is_same_file::*;
8788
pub(crate) use metadata_ext::*;
88-
pub(crate) use mkdir_unchecked::*;
8989
pub(crate) use open_options_ext::*;
9090
pub(crate) use open_unchecked::*;
9191
pub(crate) use permissions_ext::*;

cap-primitives/src/winx/fs/mkdir_unchecked.rs renamed to cap-primitives/src/winx/fs/create_dir_unchecked.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ use super::get_path::concatenate_or_return_absolute;
22
use crate::fs::DirOptions;
33
use std::{fs, io, path::Path};
44

5-
/// *Unsandboxed* function similar to `mkdir`, but which does not perform sandboxing.
5+
/// *Unsandboxed* function similar to `create_dir`, but which does not perform sandboxing.
66
///
77
/// Note that Windows doesn't have any extra flags in `DirOptions`, so the
88
/// `options` parameter is ignored.
9-
pub(crate) fn mkdir_unchecked(
9+
pub(crate) fn create_dir_unchecked(
1010
start: &fs::File,
1111
path: &Path,
1212
_options: &DirOptions,

0 commit comments

Comments
 (0)