// Traverses the whole backup directory and finds all leaf directories
// (containing no other directories). Then it purges all leaves older than the
// specified retention time.
Traverses the whole backup directory and finds all leaf directories
(containing no other directories). Then it purges all leaves older than the
specified retention time.
Traverses the whole backup directory and finds all leaf directories ( containing no other directories ) . Then it purges all leaves older than the specified retention time .
fn purge(threshold_secs: Duration, path: &Path, log: ReplicaLogger) -> Result<(), io::Error> {
    let mut leaves = Vec::new();
    get_leaves(path, &mut leaves)?;
    for path in leaves {
        let age = match path.metadata()?.modified()?.elapsed() {
            Ok(time) => time,
            // According to the documentation of `elapsed` this function may fail as
            // "the underlying system clock is susceptible to drift and updates". Those
            // errors are transient and safe to ignore. As they are very rare it's ok to
            // log a warning.
            Err(err) => {
                warn!(
                    log,
                    "Skipping {:?}, because the modified timestamp couldn't be computed: {:?}",
                    &path,
                    err
                );
                continue;
            }
        };
        if age > threshold_secs {
            fs::remove_dir_all(path)?;
        }
    }
    Ok(())
}
fn purge ( threshold_secs : Duration , path : & Path , log : ReplicaLogger ) -> Result < ( ) , io :: Error > { let mut leaves = Vec :: new ( ) ; get_leaves ( path , & mut leaves ) ? ; for path in leaves { let age = match path . metadata ( ) ? . modified ( ) ? . elapsed ( ) { Ok ( time ) => time , // According to the documentation of `elapsed` this function may fail as // "the underlying system clock is susceptible to drift and updates". Those // errors are transient and safe to ignore. As they are very rare it's ok to // log a warning. Err ( err ) => { warn ! ( log " " path err ) ; continue ; } } ; if age > threshold_secs { fs :: remove_dir_all ( path ) ? ; } } Ok ( ( ) ) }
Traverses the whole backup directory and finds all leaf directories
(containing no other directories).
Traverses the whole backup directory and finds all leaf directories ( containing no other directories ) .
threshold_secs
Duration
path
&Path
log
ReplicaLogger