Lines Matching refs:entry
77 """An entry should not have more than one protobuf extension present."""
84 def GetEntryType(entry):
88 entry: A SyncEntity protobuf object whose type to determine.
90 A value from ALL_TYPES if the entry's type can be determined, or None
93 ProtobufExtensionNotUnique: More than one type was indicated by the entry.
95 if entry.server_defined_unique_tag == TOP_LEVEL_FOLDER_TAG:
97 entry_types = GetEntryTypesFromSpecifics(entry.specifics)
283 def _SaveEntry(self, entry):
284 """Insert or update an entry in the change log, and give it a new version.
286 The ID fields of this entry are assumed to be valid server IDs. This
287 entry will be updated with a new version number and sync_timestamp.
290 entry: The entry to be added or updated.
294 # both as the per-entry version as well as the update-progress timestamp.
296 entry.version = self._version
297 entry.sync_timestamp = self._version
301 base_entry = self._entries.get(entry.id_string)
303 entry.originator_cache_guid = base_entry.originator_cache_guid
304 entry.originator_client_item_id = base_entry.originator_client_item_id
306 self._entries[entry.id_string] = DeepCopyOfProto(entry)
355 def _WritePosition(self, entry, parent_id, prev_id=None):
363 entry: The entry for which to compute a position. Its ID field are
364 assumed to be server IDs. This entry will have its parent_id_string
367 parent_id: The ID of the entry intended as the new parent.
368 prev_id: The ID of the entry intended as the new predecessor. If this
370 the entry will be positioned at the end (right) of the ordering. If
372 ordering. Otherwise, the entry will be given a position_in_parent
379 if current_limit_entry.id_string == entry.id_string:
388 if prev_id == entry.id_string:
392 entry.position_in_parent = 0
395 entry.position_in_parent = ExtendRange(siblings[0], -1)
401 elif successor.id_string == entry.id_string:
403 entry.position_in_parent = successor.position_in_parent
407 entry.position_in_parent = (item.position_in_parent * 7 +
412 entry.position_in_parent = ExtendRange(siblings[-1], +1)
414 entry.parent_id_string = parent_id
415 entry.ClearField('insert_after_item_id')
433 entry = sync_pb2.SyncEntity()
434 entry.id_string = id_string
435 entry.non_unique_name = spec.name
436 entry.name = spec.name
437 entry.server_defined_unique_tag = spec.tag
438 entry.folder = True
439 entry.deleted = False
440 entry.specifics.CopyFrom(GetDefaultEntitySpecifics(spec.sync_type))
441 self._WritePosition(entry, self._ServerTagToId(spec.parent_tag))
442 self._SaveEntry(entry)
494 def _CopyOverImmutableFields(self, entry):
498 entry: A sync entity from the client.
500 if entry.id_string in self._entries:
501 if self._entries[entry.id_string].HasField(
503 entry.server_defined_unique_tag = (
504 self._entries[entry.id_string].server_defined_unique_tag)
506 def _CheckVersionForCommit(self, entry):
513 entry: A sync entity from the client. It is assumed that ID fields
517 newest server version for the given entry.
519 if entry.id_string in self._entries:
521 return (self._entries[entry.id_string].version == entry.version or
522 self._entries[entry.id_string].deleted)
525 return entry.version == 0
527 def _CheckParentIdForCommit(self, entry):
531 entry: A sync entity from the client. It is assumed that ID fields
537 if entry.parent_id_string == ROOT_ID:
540 if entry.parent_id_string not in self._entries:
543 if entry.parent_id_string == entry.id_string:
546 if self._entries[entry.parent_id_string].deleted:
549 if not self._entries[entry.parent_id_string].folder:
554 def _RewriteIdsAsServerIds(self, entry, cache_guid, commit_session):
555 """Convert ID fields in a client sync entry to server IDs.
564 entry: The client sync entry to modify.
570 if entry.version == 0:
571 if entry.HasField('client_defined_unique_tag'):
573 new_id = self._ClientTagToId(entry.client_defined_unique_tag)
575 new_id = self._ClientIdToId(cache_guid, entry.id_string)
576 entry.originator_cache_guid = cache_guid
577 entry.originator_client_item_id = entry.id_string
578 commit_session[entry.id_string] = new_id # Remember the remapping.
579 entry.id_string = new_id
580 if entry.parent_id_string in commit_session:
581 entry.parent_id_string = commit_session[entry.parent_id_string]
582 if entry.insert_after_item_id in commit_session:
583 entry.insert_after_item_id = commit_session[entry.insert_after_item_id]
585 def CommitEntry(self, entry, cache_guid, commit_session):
586 """Attempt to commit one entry to the user's account.
589 entry: A SyncEntity protobuf representing desired object changes.
592 if the entry is new.
594 objects committed earlier this session. If the entry gets a new ID
597 A SyncEntity reflecting the post-commit value of the entry, or None
598 if the entry was not committed due to an error.
600 entry = DeepCopyOfProto(entry)
602 # Generate server IDs for this entry, and write generated server IDs
605 self._RewriteIdsAsServerIds(entry, cache_guid, commit_session)
607 # Perform the optimistic concurrency check on the entry's version number.
610 if not self._CheckVersionForCommit(entry):
615 if not self._CheckParentIdForCommit(entry):
618 self._CopyOverImmutableFields(entry);
622 # Deletion works by storing a limited record for an entry, called a
625 if entry.deleted:
627 """Make a tombstone entry that will replace the entry being deleted.
632 A new SyncEntity reflecting the fact that the entry is deleted.
645 """Check if a SyncEntity is a child of entry, or any of its children.
648 child_id: Index of the SyncEntity that is a possible child of entry.
654 if self._entries[child_id].parent_id_string == entry.id_string:
658 # Identify any children entry might have.
666 # Delete entry itself.
667 entry = MakeTombstone(entry.id_string)
678 if entry.HasField('insert_after_item_id'):
679 self._WritePosition(entry, entry.parent_id_string,
680 entry.insert_after_item_id)
682 self._WritePosition(entry, entry.parent_id_string)
686 base_entry = self._entries.get(entry.id_string)
687 if base_entry and not entry.HasField('originator_cache_guid'):
688 entry.originator_cache_guid = base_entry.originator_cache_guid
689 entry.originator_client_item_id = base_entry.originator_client_item_id
692 self._SaveEntry(entry)
693 return entry
727 This is the main entry point for this class. It is safe to call this
783 for entry in commit_message.entries:
787 server_entry = self.account.CommitEntry(entry, guid, session)
809 reply.version = entry.version + 1
825 for entry in entries:
827 reply.CopyFrom(entry)