pub async fn sync_all<S: Into<PathBuf>>(
        root: S,
        expected_ids: &[Uuid],
    ) -> anyhow::Result<Environments> {
        let root = root.into();
        let entries = read_dir(&root)?;
        let mut existing_envs: Vec<Environment> = entries
            .filter_map(|e| {
                if e.is_ok() && e.as_ref().unwrap().file_type().is_ok() {
                    e.ok()
                } else {
                    None
                }
            })
            .filter_map(|e| {
                if e.file_type().unwrap().is_dir() {
                    task::block_on(Self::get_id_from(e.path())).map(|i| (e, i))
                } else {
                    None
                }
            })
            .map(|(e, id)| task::block_on(Environment::create_with_id(e.path(), id)))
            .filter_map(Result::ok)
            .collect();

        let existing: HashSet<_> = HashSet::from_iter(existing_envs.iter().map(|e| e.id));
        let expected = HashSet::from_iter(expected_ids.iter().cloned());

        let mut remaining: Vec<Environment> = expected
            .difference(&existing)
            .map(|id| {
                task::block_on(Environment::create_with_id(
                    (&root).clone().join(id.to_string()),
                    *id,
                ))
                .unwrap()
            })
            .collect();
        remaining.append(&mut existing_envs);
        Ok(Environments::from_vec(root, remaining))
    }
///
/// Synchronizes a given directory by checking the id file
///
Synchronizes a given directory by checking the id file
Synchronizes a given directory by checking the id file
pub async fn sync_all<S: Into<PathBuf>>(
        root: S,
        expected_ids: &[Uuid],
    ) -> anyhow::Result<Environments> {
        let root = root.into();
        let entries = read_dir(&root)?;
        let mut existing_envs: Vec<Environment> = entries
            .filter_map(|e| {
                if e.is_ok() && e.as_ref().unwrap().file_type().is_ok() {
                    e.ok()
                } else {
                    None
                }
            })
            .filter_map(|e| {
                if e.file_type().unwrap().is_dir() {
                    task::block_on(Self::get_id_from(e.path())).map(|i| (e, i))
                } else {
                    None
                }
            })
            .map(|(e, id)| task::block_on(Environment::create_with_id(e.path(), id)))
            .filter_map(Result::ok)
            .collect();
        let existing: HashSet<_> = HashSet::from_iter(existing_envs.iter().map(|e| e.id));
        let expected = HashSet::from_iter(expected_ids.iter().cloned());
        let mut remaining: Vec<Environment> = expected
            .difference(&existing)
            .map(|id| {
                task::block_on(Environment::create_with_id(
                    (&root).clone().join(id.to_string()),
                    *id,
                ))
                .unwrap()
            })
            .collect();
        remaining.append(&mut existing_envs);
        Ok(Environments::from_vec(root, remaining))
    }
pub async fn sync_all < S : Into < PathBuf > > ( root : S , expected_ids : & [ Uuid ] , ) -> anyhow :: Result < Environments > { let root = root . into ( ) ; let entries = read_dir ( & root ) ? ; let mut existing_envs : Vec < Environment > = entries . filter_map ( | e | { if e . is_ok ( ) && e . as_ref ( ) . unwrap ( ) . file_type ( ) . is_ok ( ) { e . ok ( ) } else { None } } ) . filter_map ( | e | { if e . file_type ( ) . unwrap ( ) . is_dir ( ) { task :: block_on ( Self :: get_id_from ( e . path ( ) ) ) . map ( | i | ( e , i ) ) } else { None } } ) . map ( | ( e , id ) | task :: block_on ( Environment :: create_with_id ( e . path ( ) , id ) ) ) . filter_map ( Result :: ok ) . collect ( ) ; let existing : HashSet < _ > = HashSet :: from_iter ( existing_envs . iter ( ) . map ( | e | e . id ) ) ; let expected = HashSet :: from_iter ( expected_ids . iter ( ) . cloned ( ) ) ; let mut remaining : Vec < Environment > = expected . difference ( & existing ) . map ( | id | { task :: block_on ( Environment :: create_with_id ( ( & root ) . clone ( ) . join ( id . to_string ( ) ) , * id , ) ) . unwrap ( ) } ) . collect ( ) ; remaining . append ( & mut existing_envs ) ; Ok ( Environments :: from_vec ( root , remaining ) ) }
Synchronizes a given directory by checking the id file
Synchronizes a given directory by checking the id file
root
S
expected_ids
&[Uuid]
root
S
expected_ids
&[Uuid]