Detecting Conflicts in Put()

WORK IN PROGRESS

LUID Comparison With Existing Data No Existing Data
Newer Older Equal Unknown
Known Put (1) Conflict (2) Skip (3) Conflict (4) Put (5)
Unknown Conflict (2) Conflict (2) Skip (3) Conflict (4) Put (5)

Pseudo-code

def put(self, data, overwrite, LUID=None):
    DataProvider.TwoWay.put(self, data, overwrite, LUID)
    if overwrite and LUID:
        LUID = self._replace_data(LUID, data)
    else:
        if LUID and self._data_exists(LUID):
            oldData = self._get_data(LUID)
            comp = data.compare(oldData)
            #Possibility 1: If LUID != None (i.e this is a modification/update of a 
            #previous sync, and we are newer, the go ahead an put the data
            if LUID != None and comp == conduit.datatypes.COMPARISON_NEWER:
                LUID = self._replace_data(LUID, data)
            #Possibility 3: We are the same, so return either rid
            elif comp == conduit.datatypes.COMPARISON_EQUAL:
                return oldData.get_rid()
            #Possibility 2, 4: All that remains are conflicts
            else:
                raise Exceptions.SynchronizeConflictError(comp, data, oldData)
        else:
            #Possibility 5:
            LUID = self._put_data(data)

    #now return the rid
    if not LUID:
        raise Exceptions.SyncronizeError("Error putting/updating data")
    else:
        return self._get_data(LUID).get_rid()