Commit d249b8c9a8627fcf65a219ea5512ad5dae3673b6
Fix metadata-only updates for Sugar v2 API
path='' means the caller wants to update only the metadata and "inherit" the
data from the previous version.
| | | | 268 | | 268 | |
---|
269 | parent = latest_versions[0] | 269 | parent = latest_versions[0] |
---|
270 | object_id = parent['tree_id'], parent['version_id'] | 270 | object_id = parent['tree_id'], parent['version_id'] |
---|
271 | if self._compare_checksums(parent, file_path): | | if self._compare_checksums(parent, file_path): |
---|
| | 271 | if self._check_identical(parent, file_path): | 272 | self._internal_api.change_metadata(object_id, props) | 272 | self._internal_api.change_metadata(object_id, props) |
---|
273 | return success_cb(uid, None) | 273 | return success_cb(uid, None) |
---|
274 | | 274 | |
---|
… | | … | |
---|
366 | return self._internal_api.find({'tree_id': uid}, | 366 | return self._internal_api.find({'tree_id': uid}, |
---|
367 | {'limit': 1, 'order_by': ['+timestamp']})[0] | 367 | {'limit': 1, 'order_by': ['+timestamp']})[0] |
---|
368 | | 368 | |
---|
369 | def _compare_checksums(self, parent, child_data_path): | | def _compare_checksums(self, parent, child_data_path): |
---|
| | 369 | def _check_identical(self, parent, child_data_path): | | | 370 | """Check whether the new version contains the same data as the parent |
---|
| | 371 | |
---|
| | 372 | If child_data_path is empty, but the parent contains data, that's |
---|
| | 373 | interpreted as wanting to do a metadata-only update (emulating |
---|
| | 374 | sugar-datastore behaviour). |
---|
| | 375 | """ |
---|
370 | parent_object_id = (parent['tree_id'], parent['version_id']) | 376 | parent_object_id = (parent['tree_id'], parent['version_id']) |
---|
371 | parent_data_path = self._internal_api.get_data_path(parent_object_id) | 377 | parent_data_path = self._internal_api.get_data_path(parent_object_id) |
---|
372 | if bool(child_data_path) ^ bool(parent_data_path): | | if bool(child_data_path) ^ bool(parent_data_path): |
---|
373 | return False | | return False |
---|
374 | elif not child_data_path: | | elif not child_data_path: |
---|
| | 378 | if not child_data_path: | 375 | return True | 379 | return True |
---|
| | 380 | elif child_data_path and not parent_data_path: |
---|
| | 381 | return False |
---|
376 | | 382 | |
---|
| | 383 | # TODO: compare checksums? |
---|
377 | return False | 384 | return False |
---|
378 | parent_checksum = self._internal_api.get_data_checksum( | | parent_checksum = self._internal_api.get_data_checksum( |
---|
379 | parent_object_id) | | parent_object_id) |
---|
380 | child_checksum = calculate_checksum(child_data_path) | | child_checksum = calculate_checksum(child_data_path) |
---|
381 | return parent_checksum == child_checksum | | return parent_checksum == child_checksum |
---|
382 | | 385 | |
---|
383 | def __change_metadata_cb(self, (tree_id, version_id), metadata): | 386 | def __change_metadata_cb(self, (tree_id, version_id), metadata): |
---|
384 | self.Updated(tree_id) | 387 | self.Updated(tree_id) |
---|