From a111996299e093cfd734de32051e1efd68ea72c9 Mon Sep 17 00:00:00 2001 From: Benjamin Saller Date: Wed, 01 Aug 2007 17:59:09 +0000 Subject: While inplace stores should (after trial-2) return the file on the mounted media for trial 2 it was requested that they return a copy in /tmp. This broke the update method which before simply scheduled the inplace file for re-indexing. fixes #2607 --- diff --git a/src/olpc/datastore/backingstore.py b/src/olpc/datastore/backingstore.py index 2956811..47e8214 100644 --- a/src/olpc/datastore/backingstore.py +++ b/src/olpc/datastore/backingstore.py @@ -346,24 +346,11 @@ class FileBackingStore(BackingStore): if replace is False and os.path.exists(path): raise KeyError("objects with path:%s for uid:%s exists" %( - path, uid)) + path, uid)) - verify = self.options.get('verify', False) - c = None - if verify: - fp = open(path, 'w') - filelike.seek(0) - c = sha.sha() - for line in filelike: - if verify:c.update(line) - fp.write(line) - fp.close() - else: + if filelike.name != path: + # protection on inplace stores bin_copy.bin_copy(filelike.name, path) -## if verify: -## if not content: -## content = self.indexmanager.get(uid) -## content.checksum = c.hexdigest() def _checksum(self, filename): c = sha.sha() @@ -576,7 +563,29 @@ class InplaceFileBackingStore(FileBackingStore): # the file would have already been changed inplace # don't touch it props['uid'] = uid + + proposed_name = None + if filelike: + if isinstance(filelike, basestring): + # lets treat it as a filename + filelike = open(filelike, "r") + filelike.seek(0) + # usually with USB drives and the like the file we are + # indexing is already on it, however in the case of moving + # files to these devices we need to detect this case and + # place the file + proposed_name = props.get('filename', None) + if not proposed_name: + proposed_name = os.path.split(filelike.name)[1] + # record the name before qualifying it to the store + props['filename'] = proposed_name + proposed_name = os.path.join(self.uri, proposed_name) + self.indexmanager.index(props, filelike) + + if proposed_name: + self._writeContent(uid, filelike, replace=True, target=proposed_name) + def delete(self, uid): c = self.indexmanager.get(uid) -- cgit v0.9.1