fn _construct_agent_state(path: &Path) -> Result<AgentState, StateError> {
    if path.metadata()?.permissions().readonly() {
        return Err(StateError::PermissionDenied(path.into()));
    }

    let path = path.join("agent_state.db");

    let mut db_opts = Options::default();
    db_opts.create_missing_column_families(true);
    db_opts.create_if_missing(true);

    let offset_cf_opt = Options::default();
    let offset_cf = ColumnFamilyDescriptor::new(OFFSET_NAME, offset_cf_opt.clone());
    let cfs = vec![offset_cf];

    info!("Opening state db at {:?}", path);

    let db = match DB::open_cf_descriptors(&db_opts, &path, cfs) {
        Ok(db) => db,
        // Attempt to repair a badly closed DB
        Err(e) => {
            warn!("error opening state db, attempted to repair: {}", e);
            DB::repair(&db_opts, &path).map_or_else(
                |_| {
                    DB::destroy(&db_opts, &path)?;
                    DB::open_cf_descriptors(
                        &db_opts,
                        &path,
                        vec![ColumnFamilyDescriptor::new(
                            OFFSET_NAME,
                            offset_cf_opt.clone(),
                        )],
                    )
                },
                |_| {
                    DB::open_cf_descriptors(
                        &db_opts,
                        &path,
                        vec![ColumnFamilyDescriptor::new(
                            OFFSET_NAME,
                            offset_cf_opt.clone(),
                        )],
                    )
                },
            )?
        }
    };
    Ok(AgentState {
        db: Arc::new(db),
        offset_cf_opt,
    })
}
// This was the old new fn implementation. It could probably be broken up
// into a few smaller, private functions.
This was the old new fn implementation. It could probably be broken up
into a few smaller, private functions.
This was the old new fn implementation . It could probably be broken up into a few smaller private functions .
fn _construct_agent_state(path: &Path) -> Result<AgentState, StateError> {
    if path.metadata()?.permissions().readonly() {
        return Err(StateError::PermissionDenied(path.into()));
    }
    let path = path.join("agent_state.db");
    let mut db_opts = Options::default();
    db_opts.create_missing_column_families(true);
    db_opts.create_if_missing(true);
    let offset_cf_opt = Options::default();
    let offset_cf = ColumnFamilyDescriptor::new(OFFSET_NAME, offset_cf_opt.clone());
    let cfs = vec![offset_cf];
    info!("Opening state db at {:?}", path);
    let db = match DB::open_cf_descriptors(&db_opts, &path, cfs) {
        Ok(db) => db,
        // Attempt to repair a badly closed DB
        Err(e) => {
            warn!("error opening state db, attempted to repair: {}", e);
            DB::repair(&db_opts, &path).map_or_else(
                |_| {
                    DB::destroy(&db_opts, &path)?;
                    DB::open_cf_descriptors(
                        &db_opts,
                        &path,
                        vec![ColumnFamilyDescriptor::new(
                            OFFSET_NAME,
                            offset_cf_opt.clone(),
                        )],
                    )
                },
                |_| {
                    DB::open_cf_descriptors(
                        &db_opts,
                        &path,
                        vec![ColumnFamilyDescriptor::new(
                            OFFSET_NAME,
                            offset_cf_opt.clone(),
                        )],
                    )
                },
            )?
        }
    };
    Ok(AgentState {
        db: Arc::new(db),
        offset_cf_opt,
    })
}
fn _construct_agent_state ( path : & Path ) -> Result < AgentState , StateError > { if path . metadata ( ) ? . permissions ( ) . readonly ( ) { return Err ( StateError :: PermissionDenied ( path . into ( ) ) ) ; } let path = path . join ( " " ) ; let mut db_opts = Options :: default ( ) ; db_opts . create_missing_column_families ( true ) ; db_opts . create_if_missing ( true ) ; let offset_cf_opt = Options :: default ( ) ; let offset_cf = ColumnFamilyDescriptor :: new ( OFFSET_NAME , offset_cf_opt . clone ( ) ) ; let cfs = vec ! [ offset_cf ] ; info ! ( " " path ) ; let db = match DB :: open_cf_descriptors ( & db_opts , & path , cfs ) { Ok ( db ) => db , // Attempt to repair a badly closed DB Err ( e ) => { warn ! ( " " e ) ; DB :: repair ( & db_opts , & path ) . map_or_else ( | _ | { DB :: destroy ( & db_opts , & path ) ? ; DB :: open_cf_descriptors ( & db_opts , & path , vec ! [ ColumnFamilyDescriptor new ( OFFSET_NAME offset_cf_opt clone ( ) ) ] , ) } , | _ | { DB :: open_cf_descriptors ( & db_opts , & path , vec ! [ ColumnFamilyDescriptor new ( OFFSET_NAME offset_cf_opt clone ( ) ) ] , ) } , ) ? } } ; Ok ( AgentState { db : Arc :: new ( db ) , offset_cf_opt , } ) }
This was the old new fn implementation.
This was the old new fn implementation .
path
&Path
path
&Path