Function cachedir::mkdir_atomic
source · pub fn mkdir_atomic<P: AsRef<Path>>(directory: P) -> Result<bool>
Expand description
Tries to create directory
with a CACHEDIR.TAG
file atomically and returns true
if it
created it or false
if the directory already exists, regardless of if the CACHEDIR.TAG
file exists in it or if it has the correct header.
This function first creates a temporary directory in the same directory where directory
is
supposed to exist. The temporary directory has a semi-random name based on the directory
base
name. Then the CACHEDIR.TAG
file is created in the temporary directory and the temporary
directory is attempted to be renamed to directory
. This (as opposed to creating the directory
with the final name and creating CACHEDIR.TAG
file in it) is a way to ensure that the
directory
is always created with the CACHEDIR.TAG
file. If we simply created the directory
with the final name the program could be interrupted before CACHEDIR.TAG
creation and the
directory
would remain not excluded from backups as this function does not attempt to verify
or change the CACHEDIR.TAG
file in directory
if it already exists.