diff --git a/proxmox-tools/src/fs.rs b/proxmox-tools/src/fs.rs index cb6b30d3..98cd3d26 100644 --- a/proxmox-tools/src/fs.rs +++ b/proxmox-tools/src/fs.rs @@ -240,6 +240,9 @@ pub fn create_dir>(path: P, options: CreateOptions) -> Result<(), /// Recursively create a path with separately defined metadata for intermediate directories and the /// final component in the path. /// +/// Returns `true` if the final directory was created. Otherwise `false` is returned and no changes +/// to the directory's metadata have been performed. +/// /// ```no_run /// # use nix::sys::stat::Mode; /// # use nix::unistd::{Gid, Uid}; @@ -260,7 +263,7 @@ pub fn create_path>( path: P, intermediate_opts: Option, final_opts: Option, -) -> Result<(), Error> { +) -> Result { create_path_do(path.as_ref(), intermediate_opts, final_opts) } @@ -268,7 +271,7 @@ fn create_path_do( path: &Path, intermediate_opts: Option, final_opts: Option, -) -> Result<(), Error> { +) -> Result { use std::path::Component; let mut iter = path.components().peekable(); @@ -309,12 +312,13 @@ fn create_path_at_do( mut iter: std::iter::Peekable, intermediate_opts: Option, final_opts: Option, -) -> Result<(), Error> { +) -> Result { + let mut created = false; loop { use std::path::Component; match iter.next() { - None => return Ok(()), + None => return Ok(created), Some(Component::ParentDir) => { at = Fd::openat( @@ -338,7 +342,7 @@ fn create_path_at_do( .and_then(|o| o.perm) .unwrap_or(stat::Mode::from_bits_truncate(0o755)); - let created = match stat::mkdirat(at.as_raw_fd(), path, mode) { + created = match stat::mkdirat(at.as_raw_fd(), path, mode) { Err(nix::Error::Sys(Errno::EEXIST)) => false, Err(e) => return Err(e.into()), Ok(_) => true,