Web · Wiki · Activities · Blog · Lists · Chat · Meeting · Bugs · Git · Translate · Archive · People · Donate

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.
  
268268
269269 parent = latest_versions[0]
270270 object_id = parent['tree_id'], parent['version_id']
271 if self._compare_checksums(parent, file_path):
271 if self._check_identical(parent, file_path):
272272 self._internal_api.change_metadata(object_id, props)
273273 return success_cb(uid, None)
274274
366366 return self._internal_api.find({'tree_id': uid},
367367 {'limit': 1, 'order_by': ['+timestamp']})[0]
368368
369 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 """
370376 parent_object_id = (parent['tree_id'], parent['version_id'])
371377 parent_data_path = self._internal_api.get_data_path(parent_object_id)
372 if bool(child_data_path) ^ bool(parent_data_path):
373 return False
374 elif not child_data_path:
378 if not child_data_path:
375379 return True
380 elif child_data_path and not parent_data_path:
381 return False
376382
383 # TODO: compare checksums?
377384 return False
378 parent_checksum = self._internal_api.get_data_checksum(
379 parent_object_id)
380 child_checksum = calculate_checksum(child_data_path)
381 return parent_checksum == child_checksum
382385
383386 def __change_metadata_cb(self, (tree_id, version_id), metadata):
384387 self.Updated(tree_id)