From 0a7e80f01ac0f96b15d1eeeda3386be40b8a9b7c Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Sun, 09 Sep 2007 04:15:20 +0000 Subject: Fix duplicate datastore entries on item creation caused by last commit --- diff --git a/NEWS b/NEWS index da00958..1f0c716 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,4 @@ +* Fix duplicate datastore entries on item creation caused by last commit * On update() and create(), copy asynchronously where possible, and add new "transfer_ownership" argument to update() and create() that allow the datastore to move the object rather than copy it (dcbw) diff --git a/src/olpc/datastore/backingstore.py b/src/olpc/datastore/backingstore.py index 886f34f..cc9b841 100644 --- a/src/olpc/datastore/backingstore.py +++ b/src/olpc/datastore/backingstore.py @@ -450,7 +450,7 @@ class FileBackingStore(BackingStore): return try: # Index the content this time - uid = self.indexmanager.index(props, path) + self.indexmanager.index(props, path) completion(None, uid) except Exception, exc: completion(exc) @@ -459,6 +459,7 @@ class FileBackingStore(BackingStore): if completion is None: raise RuntimeError("Completion must be valid for async create") uid = self.indexmanager.index(props) + props['uid'] = uid if filelike: if isinstance(filelike, basestring): # lets treat it as a filename @@ -471,13 +472,15 @@ class FileBackingStore(BackingStore): def create(self, props, filelike, can_move=False): if filelike: - uid = self.indexmanager.index(props, None) + uid = self.indexmanager.index(props) + props['uid'] = uid if isinstance(filelike, basestring): # lets treat it as a filename filelike = open(filelike, "r") filelike.seek(0) path = self._writeContent(uid, filelike, replace=False, can_move=can_move) - return self.indexmanager.index(props, path) + self.indexmanager.index(props, path) + return uid else: return self.indexmanager.index(props) @@ -511,8 +514,8 @@ class FileBackingStore(BackingStore): raise RuntimeError("Filelike must be valid for async update") if completion is None: raise RuntimeError("Completion must be valid for async update") - if 'uid' not in props: props['uid'] = uid + props['uid'] = uid if filelike: if isinstance(filelike, basestring): # lets treat it as a filename @@ -524,7 +527,7 @@ class FileBackingStore(BackingStore): completion() def update(self, uid, props, filelike=None, can_move=False): - if 'uid' not in props: props['uid'] = uid + props['uid'] = uid if filelike: if isinstance(filelike, basestring): # lets treat it as a filename @@ -694,12 +697,14 @@ class InplaceFileBackingStore(FileBackingStore): props['filename'] = proposed_name proposed_name = os.path.join(self.uri, proposed_name) - uid = self.indexmanager.index(props, None) + uid = self.indexmanager.index(props) + props['uid'] = uid path = filelike if proposed_name and not os.path.exists(proposed_name): path = self._writeContent(uid, filelike, replace=False, target=proposed_name) - return self.indexmanager.index(props, path) - + self.indexmanager.index(props, path) + return uid + def get(self, uid, env=None, allowMissing=False): content = self.indexmanager.get(uid) if not content: raise KeyError(uid) -- cgit v0.9.1