fn register()

in src/reconfig.rs [115:157]


    fn register(&mut self, request: &Request) -> Fallible<Prefixes> {
        let mut used_prefixes: HashMap<u32, PathBuf> = HashMap::new();

        if let Request::CreateSandbox(request) = &request {
            let mut count = 0;
            for (id, path) in &request.prefixes {
                let id = id.parse::<u32>().context("Bad prefix number")?;
                match self.data.entry(id) {
                    Entry::Occupied(e) => {
                        let previous_path = e.get();
                        if previous_path != path {
                            return Err(format_err!("Prefix {} already had path {} but got new {}",
                                id, previous_path.display(), path.display()));
                        }
                    },
                    Entry::Vacant(e) => {
                        e.insert(path.clone());
                        count += 1;
                    },
                };
            }
            if count > 0 {
                info!("Registered {} new prefixes", count);
            }

            for m in &request.mappings {
                match self.data.get(&m.path_prefix) {
                    Some(prefix) => used_prefixes.entry(m.path_prefix)
                        .or_insert_with(|| prefix.clone()),
                    None => return Err(format_err!("Prefix {} does not exist", m.path_prefix)),
                };

                match self.data.get(&m.underlying_path_prefix) {
                    Some(prefix) => used_prefixes.entry(m.underlying_path_prefix)
                        .or_insert_with(|| prefix.clone()),
                    None => return
                        Err(format_err!("Prefix {} does not exist", m.underlying_path_prefix)),
                };
            }
        }

        Ok(Prefixes { data: used_prefixes })
    }