Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Saller <bcsaller@objectrealms.net>2007-08-01 17:59:09 (GMT)
committer Benjamin Saller <bcsaller@objectrealms.net>2007-08-01 17:59:09 (GMT)
commita111996299e093cfd734de32051e1efd68ea72c9 (patch)
tree1e0d15a1d0325f3a214af4d02f769b02c5c771da
parent45391ed941b59c5e2fd0706c6ba05ecf06b7a0e8 (diff)
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
-rw-r--r--src/olpc/datastore/backingstore.py41
1 files changed, 25 insertions, 16 deletions
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)