Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: smol-rs/async-fs
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.1.1
Choose a base ref
...
head repository: smol-rs/async-fs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.1.2
Choose a head ref
  • 2 commits
  • 3 files changed
  • 2 contributors

Commits on Apr 20, 2024

  1. fix(docs): create_dir_all doesn't error if path already exists

    ThinkChaos authored Apr 20, 2024
    Copy the full SHA
    c058784 View commit details

Commits on Apr 27, 2024

  1. v2.1.2

    Signed-off-by: John Nunley <dev@notgull.net>
    notgull authored Apr 27, 2024
    Copy the full SHA
    6eee6bc View commit details
Showing with 61 additions and 20 deletions.
  1. +5 −0 CHANGELOG.md
  2. +1 −1 Cargo.toml
  3. +55 −19 src/lib.rs
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Version 2.1.2

- Ensure that the docs for `create_dir_all` are close to the equivalent function
in libstd. (#35)

# Version 2.1.1

- Fix a copy/paste error in documentation. (#33)
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ name = "async-fs"
# When publishing a new version:
# - Update CHANGELOG.md
# - Create "v2.x.y" git tag
version = "2.1.1"
version = "2.1.2"
authors = ["Stjepan Glavina <stjepang@gmail.com>"]
edition = "2018"
rust-version = "1.63"
74 changes: 55 additions & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -114,48 +114,84 @@ pub async fn copy<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<
unblock(move || std::fs::copy(&src, &dst)).await
}

/// Creates a directory.
/// Creates a new, empty directory at the provided path
///
/// Note that this function will only create the final directory in `path`. If you want to create
/// all of its missing parent directories too, use [`create_dir_all()`] instead.
/// # Platform-specific behavior
///
/// This function currently corresponds to the `mkdir` function on Unix
/// and the `CreateDirectory` function on Windows.
/// Note that, this [may change in the future][changes].
///
/// [changes]: io#platform-specific-behavior
///
/// **NOTE**: If a parent of the given path doesn't exist, this function will
/// return an error. To create a directory and all its missing parents at the
/// same time, use the [`create_dir_all`] function.
///
/// # Errors
///
/// An error will be returned in the following situations:
/// This function will return an error in the following situations, but is not
/// limited to just these cases:
///
/// * `path` already points to an existing file or directory.
/// * A parent directory in `path` does not exist.
/// * The current process lacks permissions to create the directory.
/// * Some other I/O error occurred.
/// * User lacks permissions to create directory at `path`.
/// * A parent of the given path doesn't exist. (To create a directory and all
/// its missing parents at the same time, use the [`create_dir_all`]
/// function.)
/// * `path` already exists.
///
/// # Examples
///
/// ```no_run
/// # futures_lite::future::block_on(async {
/// async_fs::create_dir("./some/directory").await?;
/// # std::io::Result::Ok(()) });
/// use std::fs;
///
/// fn main() -> std::io::Result<()> {
/// fs::create_dir("/some/dir")?;
/// Ok(())
/// }
/// ```
pub async fn create_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
let path = path.as_ref().to_owned();
unblock(move || std::fs::create_dir(path)).await
}

/// Creates a directory and its parent directories if they are missing.
/// Recursively create a directory and all of its parent components if they
/// are missing.
///
/// # Platform-specific behavior
///
/// This function currently corresponds to the `mkdir` function on Unix
/// and the `CreateDirectory` function on Windows.
/// Note that, this [may change in the future][changes].
///
/// [changes]: io#platform-specific-behavior
///
/// # Errors
///
/// An error will be returned in the following situations:
/// This function will return an error in the following situations, but is not
/// limited to just these cases:
///
/// * `path` already points to an existing file or directory.
/// * The current process lacks permissions to create the directory or its missing parents.
/// * Some other I/O error occurred.
/// * If any directory in the path specified by `path`
/// does not already exist and it could not be created otherwise. The specific
/// error conditions for when a directory is being created (after it is
/// determined to not exist) are outlined by [`fs::create_dir`].
///
/// Notable exception is made for situations where any of the directories
/// specified in the `path` could not be created as it was being created concurrently.
/// Such cases are considered to be successful. That is, calling `create_dir_all`
/// concurrently from multiple threads or processes is guaranteed not to fail
/// due to a race condition with itself.
///
/// [`fs::create_dir`]: create_dir
///
/// # Examples
///
/// ```no_run
/// # futures_lite::future::block_on(async {
/// async_fs::create_dir_all("./some/directory").await?;
/// # std::io::Result::Ok(()) });
/// use std::fs;
///
/// fn main() -> std::io::Result<()> {
/// fs::create_dir_all("/some/dir")?;
/// Ok(())
/// }
/// ```
pub async fn create_dir_all<P: AsRef<Path>>(path: P) -> io::Result<()> {
let path = path.as_ref().to_owned();