Commit d249b8c9a8627fcf65a219ea5512ad5dae3673b6
- Diff rendering mode:
- inline
- side by side
gdatastore/datastore.py
(12 / 9)
  | |||
268 | 268 | ||
269 | 269 | parent = latest_versions[0] | |
270 | 270 | object_id = parent['tree_id'], parent['version_id'] | |
271 | if self._compare_checksums(parent, file_path): | ||
271 | if self._check_identical(parent, file_path): | ||
272 | 272 | self._internal_api.change_metadata(object_id, props) | |
273 | 273 | return success_cb(uid, None) | |
274 | 274 | ||
… | … | ||
366 | 366 | return self._internal_api.find({'tree_id': uid}, | |
367 | 367 | {'limit': 1, 'order_by': ['+timestamp']})[0] | |
368 | 368 | ||
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 | """ | ||
370 | 376 | parent_object_id = (parent['tree_id'], parent['version_id']) | |
371 | 377 | 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: | ||
375 | 379 | return True | |
380 | elif child_data_path and not parent_data_path: | ||
381 | return False | ||
376 | 382 | ||
383 | # TODO: compare checksums? | ||
377 | 384 | 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 | ||
382 | 385 | ||
383 | 386 | def __change_metadata_cb(self, (tree_id, version_id), metadata): | |
384 | 387 | self.Updated(tree_id) |