fn create_dir(&mut self, path: &Path, _entries: &mut EntryMap) -> FsResult<EntryKey> {
        let mut m_entry = self.root;

        let components = into_components(path);

        // If the path has no parents return root as the parent.
        // This commonly occurs with paths in the filesystem root, e.g /some.file or /somedir
        if components.is_empty() {
            return Ok(m_entry);
        }

        enum Action {
            Return(EntryKey),
            Lookup(PathBuf),
            CreateSymlink(PathBuf),
            CreateDir,
        }

        for (i, component) in components.iter().enumerate().skip(1) {
            let current_path = PathBuf::from_iter(&components[0..=i]);

            let action = match _entries
                .get_mut(m_entry)
                .ok_or(Error::ParentLookup)?
                .children_mut()
                .ok_or(Error::ParentNotValid)?
                .entry(component.clone())
            {
                HashMapEntry::Occupied(v) => {
                    let entry_key = *v.get();
                    let existing_entry = _entries.get(entry_key).ok_or(Error::Lookup)?;

                    match existing_entry.deref() {
                        Entry::Symlink { link, .. } => Action::Lookup(link.clone()),
                        _ => Action::Return(entry_key),
                    }
                }
                HashMapEntry::Vacant(_) => match current_path.read_link() {
                    Ok(real) => Action::CreateSymlink(real),
                    Err(_) => Action::CreateDir,
                },
            };

            let new_entry = match action {
                Action::Return(key) => key,
                Action::Lookup(ref link) => self.lookup(link, _entries).ok_or(Error::Lookup)?,
                Action::CreateDir => {
                    let wd = self
                        .watcher
                        .watch(&current_path)
                        .map_err(|e| Error::Watch(current_path.to_owned(), e))?;

                    let new_entry = Entry::Dir {
                        name: component.clone(),
                        parent: Some(m_entry),
                        children: HashMap::new(),
                        wd,
                    };

                    self.register_as_child(m_entry, new_entry, _entries)?
                }
                Action::CreateSymlink(real) => {
                    let wd = self
                        .watcher
                        .watch(&current_path)
                        .map_err(|e| Error::Watch(current_path.to_owned(), e))?;

                    let new_entry = Entry::Symlink {
                        name: component.clone(),
                        parent: m_entry,
                        link: real.clone(),
                        wd,
                        rules: into_rules(real.clone()),
                    };

                    self.register_as_child(m_entry, new_entry, _entries)?;
                    self.create_dir(&real, _entries)?
                }
            };

            m_entry = new_entry;
        }
        Ok(m_entry)
    }
// Creates all entries for a directory.
// If one of the entries already exists, it is skipped over.
// The returns a linked list of all entries.
Creates all entries for a directory.
If one of the entries already exists, it is skipped over.
The returns a linked list of all entries.
Creates all entries for a directory . If one of the entries already exists it is skipped over . The returns a linked list of all entries .
fn create_dir(&mut self, path: &Path, _entries: &mut EntryMap) -> FsResult<EntryKey> {
        let mut m_entry = self.root;
        let components = into_components(path);
        // If the path has no parents return root as the parent.
        // This commonly occurs with paths in the filesystem root, e.g /some.file or /somedir
        if components.is_empty() {
            return Ok(m_entry);
        }
        enum Action {
            Return(EntryKey),
            Lookup(PathBuf),
            CreateSymlink(PathBuf),
            CreateDir,
        }
        for (i, component) in components.iter().enumerate().skip(1) {
            let current_path = PathBuf::from_iter(&components[0..=i]);
            let action = match _entries
                .get_mut(m_entry)
                .ok_or(Error::ParentLookup)?
                .children_mut()
                .ok_or(Error::ParentNotValid)?
                .entry(component.clone())
            {
                HashMapEntry::Occupied(v) => {
                    let entry_key = *v.get();
                    let existing_entry = _entries.get(entry_key).ok_or(Error::Lookup)?;
                    match existing_entry.deref() {
                        Entry::Symlink { link, .. } => Action::Lookup(link.clone()),
                        _ => Action::Return(entry_key),
                    }
                }
                HashMapEntry::Vacant(_) => match current_path.read_link() {
                    Ok(real) => Action::CreateSymlink(real),
                    Err(_) => Action::CreateDir,
                },
            };
            let new_entry = match action {
                Action::Return(key) => key,
                Action::Lookup(ref link) => self.lookup(link, _entries).ok_or(Error::Lookup)?,
                Action::CreateDir => {
                    let wd = self
                        .watcher
                        .watch(&current_path)
                        .map_err(|e| Error::Watch(current_path.to_owned(), e))?;
                    let new_entry = Entry::Dir {
                        name: component.clone(),
                        parent: Some(m_entry),
                        children: HashMap::new(),
                        wd,
                    };
                    self.register_as_child(m_entry, new_entry, _entries)?
                }
                Action::CreateSymlink(real) => {
                    let wd = self
                        .watcher
                        .watch(&current_path)
                        .map_err(|e| Error::Watch(current_path.to_owned(), e))?;
                    let new_entry = Entry::Symlink {
                        name: component.clone(),
                        parent: m_entry,
                        link: real.clone(),
                        wd,
                        rules: into_rules(real.clone()),
                    };
                    self.register_as_child(m_entry, new_entry, _entries)?;
                    self.create_dir(&real, _entries)?
                }
            };
            m_entry = new_entry;
        }
        Ok(m_entry)
    }
fn create_dir ( & mut self , path : & Path , _entries : & mut EntryMap ) -> FsResult < EntryKey > { let mut m_entry = self . root ; let components = into_components ( path ) ; // If the path has no parents return root as the parent. // This commonly occurs with paths in the filesystem root, e.g /some.file or /somedir if components . is_empty ( ) { return Ok ( m_entry ) ; } enum Action { Return ( EntryKey ) , Lookup ( PathBuf ) , CreateSymlink ( PathBuf ) , CreateDir , } for ( i , component ) in components . iter ( ) . enumerate ( ) . skip ( 1 ) { let current_path = PathBuf :: from_iter ( & components [ 0 ..= i ] ) ; let action = match _entries . get_mut ( m_entry ) . ok_or ( Error :: ParentLookup ) ? . children_mut ( ) . ok_or ( Error :: ParentNotValid ) ? . entry ( component . clone ( ) ) { HashMapEntry :: Occupied ( v ) => { let entry_key = * v . get ( ) ; let existing_entry = _entries . get ( entry_key ) . ok_or ( Error :: Lookup ) ? ; match existing_entry . deref ( ) { Entry :: Symlink { link , .. } => Action :: Lookup ( link . clone ( ) ) , _ => Action :: Return ( entry_key ) , } } HashMapEntry :: Vacant ( _ ) => match current_path . read_link ( ) { Ok ( real ) => Action :: CreateSymlink ( real ) , Err ( _ ) => Action :: CreateDir , } , } ; let new_entry = match action { Action :: Return ( key ) => key , Action :: Lookup ( ref link ) => self . lookup ( link , _entries ) . ok_or ( Error :: Lookup ) ? , Action :: CreateDir => { let wd = self . watcher . watch ( & current_path ) . map_err ( | e | Error :: Watch ( current_path . to_owned ( ) , e ) ) ? ; let new_entry = Entry :: Dir { name : component . clone ( ) , parent : Some ( m_entry ) , children : HashMap :: new ( ) , wd , } ; self . register_as_child ( m_entry , new_entry , _entries ) ? } Action :: CreateSymlink ( real ) => { let wd = self . watcher . watch ( & current_path ) . map_err ( | e | Error :: Watch ( current_path . to_owned ( ) , e ) ) ? ; let new_entry = Entry :: Symlink { name : component . clone ( ) , parent : m_entry , link : real . clone ( ) , wd , rules : into_rules ( real . clone ( ) ) , } ; self . register_as_child ( m_entry , new_entry , _entries ) ? ; self . create_dir ( & real , _entries ) ? } } ; m_entry = new_entry ; } Ok ( m_entry ) }
Creates all entries for a directory.
Creates all entries for a directory .
&mut self
path
&Path
_entries
&mut EntryMap
&mut self
path
&Path
_entries
&mut EntryMap