--- a/gdatastore/datastore.py +++ b/gdatastore/datastore.py @@ -268,7 +268,7 @@ parent = latest_versions[0] object_id = parent['tree_id'], parent['version_id'] - if self._compare_checksums(parent, file_path): + if self._check_identical(parent, file_path): self._internal_api.change_metadata(object_id, props) return success_cb(uid, None) @@ -366,19 +366,22 @@ return self._internal_api.find({'tree_id': uid}, {'limit': 1, 'order_by': ['+timestamp']})[0] - def _compare_checksums(self, parent, child_data_path): + def _check_identical(self, parent, child_data_path): + """Check whether the new version contains the same data as the parent + + If child_data_path is empty, but the parent contains data, that's + interpreted as wanting to do a metadata-only update (emulating + sugar-datastore behaviour). + """ parent_object_id = (parent['tree_id'], parent['version_id']) parent_data_path = self._internal_api.get_data_path(parent_object_id) - if bool(child_data_path) ^ bool(parent_data_path): - return False - elif not child_data_path: + if not child_data_path: return True + elif child_data_path and not parent_data_path: + return False + # TODO: compare checksums? return False - parent_checksum = self._internal_api.get_data_checksum( - parent_object_id) - child_checksum = calculate_checksum(child_data_path) - return parent_checksum == child_checksum def __change_metadata_cb(self, (tree_id, version_id), metadata): self.Updated(tree_id)