diff options
author | Sascha Silbe <sascha-pgp@silbe.org> | 2012-02-20 16:47:09 (GMT) |
---|---|---|
committer | Sascha Silbe <sascha-pgp@silbe.org> | 2012-02-20 16:47:09 (GMT) |
commit | ad061c03425e567c4ccd727157af6749b803407d (patch) | |
tree | 599ac3ee1400540ad516f126ca5de0fbbb5da5e8 | |
parent | 7023b15eb1c40670b463c6fbb6efd02f9b2c8d2c (diff) |
Allow restoring root version even if non-root versions already exist
Restoring a version that has no parent with a tree_id that we already have
entries for can be indicative of a bug in the caller (restoring entries in
the wrong order) and causes inconsistencies in the git repository (as the
root commits don't match). For that reason, we refused to store the (new) root
version.
However under certain conditions the above can happen even without any
component being broken: Since we allow the user to delete individual versions,
the root version may have been deleted even if more recent entries were kept.
If the user took a backup before deleting the root version and tries to
restore this backup, restore() will encounter exactly the situation described
above.
Explicitly skipping this check for restore() suffices for now, but we should
reexamine our usage of git (branches) when adding support for recovering from
a broken Xapian index.
-rw-r--r-- | gdatastore/datastore.py | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/gdatastore/datastore.py b/gdatastore/datastore.py index 62489a0..4b5064f 100644 --- a/gdatastore/datastore.py +++ b/gdatastore/datastore.py @@ -190,14 +190,13 @@ class DBusApiNativeV1(dbus.service.Object): """ - add a new version with the given ids - there must be no existing entry with the same (tree_id, version_id) - - if parent_id = '', there must be no existing entry with the same tree_id and no parent_id """ if not tree_id: raise ValueError('No tree_id given') metadata['version_id'] = version_id self._internal_api.save(tree_id, parent_id, metadata, data_path, - delete_after=True, + delete_after=True, allow_new_parent=True, async_cb=async_cb, async_err_cb=async_err_cb) @@ -478,7 +477,7 @@ class InternalApi(object): return self._index.retrieve(object_id) def save(self, tree_id, parent_id, metadata, path, delete_after, async_cb, - async_err_cb): + async_err_cb, allow_new_parent=False): logging.debug('save(%r, %r, %r, %r, %r)', tree_id, parent_id, metadata, path, delete_after) @@ -493,7 +492,7 @@ class InternalApi(object): if (not tree_id) and parent_id: raise ValueError('tree_id is empty but parent_id is not') - if tree_id and not parent_id: + if tree_id and not parent_id and not allow_new_parent: if self.find({'tree_id': tree_id}, {'limit': 1})[1]: raise ValueError('No parent_id given but tree_id already ' 'exists') |