Skip to main content

prepare_file_path

Function prepare_file_path 

Source
pub fn prepare_file_path(path: &Path) -> Result<(), Error>
Expand description

Prepares a path for writing by removing any existing file and creating necessary directories.

This function:

  1. Removes the file if it already exists, and accepts a file that is already gone: the guarantee is that nothing sits at path afterwards
  2. Creates all parent directories if they don’t exist

§Arguments

  • path - The path where the file will be written

§Returns

  • Result<(), std::io::Error> - Ok if successful, or an IoError if it failed

§Errors

Returns std::io::Error when the target file exists but cannot be removed, or when the parent directory cannot be created (typically PermissionDenied, NotFound on a broken symlink ancestor, or the platform-specific disk-full case).