fn add(&mut self, op: &Op, block_id: &BlockId, timestamp: Timestamp) -> Result<()> {
        let child_path = Path::new(op.get_path()).ok_or_else(|| {
            ErrorKind::PathInvalid(format!("bad path: {}", op.get_path()))
        })?;

        let parent_path = child_path.parent();
        let child_class = Class::from_object(op.get_object()).ok_or_else(|| {
            ErrorKind::TypeInvalid(format!("bad object type: {:?}", op.get_object()))
        })?;

        let (parent_id, entry_id) = match parent_path {
            Some(path) => {
                let parent_entry = self.get_entry(path)?;

                if !parent_entry.class.allows_child(&child_class) {
                    let msg = format!(
                        "{:?} does not allow {:?} as child",
                        parent_entry.class,
                        child_class
                    );
                    return Err(ErrorKind::StructureInvalid(msg).into());
                }

                let next_id = self.next_entry_id;
                self.next_entry_id = next_id.next();

                (parent_entry.id, next_id)
            }
            None => {
                if child_class != Class::Root {
                    let msg = format!("{:?} not allowed as root entry", child_class);
                    return Err(ErrorKind::StructureInvalid(msg).into());
                }

                (EntryId::root(), EntryId::root())
            }
        };

        let mut metadata = Metadata::new();

        metadata.set_created_id(Vec::from(block_id.as_ref()));
        metadata.set_updated_id(Vec::from(block_id.as_ref()));
        metadata.set_created_at(timestamp.to_int());
        metadata.set_updated_at(timestamp.to_int());

        let entry = Entry::from_object(&mut op.get_object().clone())
            .ok_or_else(|| {
                ErrorKind::SerializationFailure("unsupported object type".to_string())
            })?;

        let entry = SerializedEntry {
            id: entry_id,
            class: child_class,
            data: &entry.serialize()?,
        };

        let entry_name = child_path.entry_name().ok_or_else(|| {
            ErrorKind::PathInvalid(format!("missing entry name: {:?}", child_path))
        })?;

        // NOTE: The underlying adapter must handle Error::EntryAlreadyExists
        self.adapter.add_entry(
            &mut self.txn,
            &entry,
            entry_name,
            parent_id,
            &metadata,
        )?;

        let new_entry = TransformEntry {
            id: entry_id,
            class: child_class,
        };

        self.new_entries.insert(child_path.to_owned(), new_entry);

        Ok(())
    }
/// Add a new entry to the directory tree
Add a new entry to the directory tree
Add a new entry to the directory tree
fn add(&mut self, op: &Op, block_id: &BlockId, timestamp: Timestamp) -> Result<()> {
        let child_path = Path::new(op.get_path()).ok_or_else(|| {
            ErrorKind::PathInvalid(format!("bad path: {}", op.get_path()))
        })?;
        let parent_path = child_path.parent();
        let child_class = Class::from_object(op.get_object()).ok_or_else(|| {
            ErrorKind::TypeInvalid(format!("bad object type: {:?}", op.get_object()))
        })?;
        let (parent_id, entry_id) = match parent_path {
            Some(path) => {
                let parent_entry = self.get_entry(path)?;
                if !parent_entry.class.allows_child(&child_class) {
                    let msg = format!(
                        "{:?} does not allow {:?} as child",
                        parent_entry.class,
                        child_class
                    );
                    return Err(ErrorKind::StructureInvalid(msg).into());
                }
                let next_id = self.next_entry_id;
                self.next_entry_id = next_id.next();
                (parent_entry.id, next_id)
            }
            None => {
                if child_class != Class::Root {
                    let msg = format!("{:?} not allowed as root entry", child_class);
                    return Err(ErrorKind::StructureInvalid(msg).into());
                }
                (EntryId::root(), EntryId::root())
            }
        };
        let mut metadata = Metadata::new();
        metadata.set_created_id(Vec::from(block_id.as_ref()));
        metadata.set_updated_id(Vec::from(block_id.as_ref()));
        metadata.set_created_at(timestamp.to_int());
        metadata.set_updated_at(timestamp.to_int());
        let entry = Entry::from_object(&mut op.get_object().clone())
            .ok_or_else(|| {
                ErrorKind::SerializationFailure("unsupported object type".to_string())
            })?;
        let entry = SerializedEntry {
            id: entry_id,
            class: child_class,
            data: &entry.serialize()?,
        };
        let entry_name = child_path.entry_name().ok_or_else(|| {
            ErrorKind::PathInvalid(format!("missing entry name: {:?}", child_path))
        })?;
        // NOTE: The underlying adapter must handle Error::EntryAlreadyExists
        self.adapter.add_entry(
            &mut self.txn,
            &entry,
            entry_name,
            parent_id,
            &metadata,
        )?;
        let new_entry = TransformEntry {
            id: entry_id,
            class: child_class,
        };
        self.new_entries.insert(child_path.to_owned(), new_entry);
        Ok(())
    }
fn add ( & mut self , op : & Op , block_id : & BlockId , timestamp : Timestamp ) -> Result < ( ) > { let child_path = Path :: new ( op . get_path ( ) ) . ok_or_else ( | | { ErrorKind :: PathInvalid ( format ! ( " " op get_path ( ) ) ) } ) ? ; let parent_path = child_path . parent ( ) ; let child_class = Class :: from_object ( op . get_object ( ) ) . ok_or_else ( | | { ErrorKind :: TypeInvalid ( format ! ( " " op get_object ( ) ) ) } ) ? ; let ( parent_id , entry_id ) = match parent_path { Some ( path ) => { let parent_entry = self . get_entry ( path ) ? ; if ! parent_entry . class . allows_child ( & child_class ) { let msg = format ! ( " " parent_entry class child_class ) ; return Err ( ErrorKind :: StructureInvalid ( msg ) . into ( ) ) ; } let next_id = self . next_entry_id ; self . next_entry_id = next_id . next ( ) ; ( parent_entry . id , next_id ) } None => { if child_class != Class :: Root { let msg = format ! ( " " child_class ) ; return Err ( ErrorKind :: StructureInvalid ( msg ) . into ( ) ) ; } ( EntryId :: root ( ) , EntryId :: root ( ) ) } } ; let mut metadata = Metadata :: new ( ) ; metadata . set_created_id ( Vec :: from ( block_id . as_ref ( ) ) ) ; metadata . set_updated_id ( Vec :: from ( block_id . as_ref ( ) ) ) ; metadata . set_created_at ( timestamp . to_int ( ) ) ; metadata . set_updated_at ( timestamp . to_int ( ) ) ; let entry = Entry :: from_object ( & mut op . get_object ( ) . clone ( ) ) . ok_or_else ( | | { ErrorKind :: SerializationFailure ( " " . to_string ( ) ) } ) ? ; let entry = SerializedEntry { id : entry_id , class : child_class , data : & entry . serialize ( ) ? , } ; let entry_name = child_path . entry_name ( ) . ok_or_else ( | | { ErrorKind :: PathInvalid ( format ! ( " " child_path ) ) } ) ? ; // NOTE: The underlying adapter must handle Error::EntryAlreadyExists self . adapter . add_entry ( & mut self . txn , & entry , entry_name , parent_id , & metadata , ) ? ; let new_entry = TransformEntry { id : entry_id , class : child_class , } ; self . new_entries . insert ( child_path . to_owned ( ) , new_entry ) ; Ok ( ( ) ) }
Add a new entry to the directory tree
Add a new entry to the directory tree
&mut self
op
&Op
block_id
&BlockId
timestamp
Timestamp
&mut self
op
&Op
block_id
&BlockId
timestamp
Timestamp