Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/olpc/datastore/backingstore.py
diff options
context:
space:
mode:
authorBenjamin Saller <bcsaller@objectrealms.net>2007-06-24 17:54:16 (GMT)
committer Benjamin Saller <bcsaller@objectrealms.net>2007-06-24 17:54:16 (GMT)
commite7ca4d9a939391cacf842742aea59fa1bd47e6e6 (patch)
tree81e4d9a59302afca72b866576b97953d43052057 /src/olpc/datastore/backingstore.py
parent84fdcc41b9d4663fd375c8af552930c197bd450a (diff)
honor mimetype when available
Diffstat (limited to 'src/olpc/datastore/backingstore.py')
-rw-r--r--src/olpc/datastore/backingstore.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/olpc/datastore/backingstore.py b/src/olpc/datastore/backingstore.py
index 67b231b..d94c6b8 100644
--- a/src/olpc/datastore/backingstore.py
+++ b/src/olpc/datastore/backingstore.py
@@ -13,12 +13,15 @@ __license__ = 'The GNU Public License V2+'
import cPickle as pickle
import sha
import os
+import re
import subprocess
import time
from olpc.datastore import query
from olpc.datastore import utils
+# changing this pattern impacts _targetFile
+filename_attempt_pattern = re.compile('\(\d+\)$')
class BackingStore(object):
"""Backing stores manage stable storage. We abstract out the
@@ -236,12 +239,17 @@ class FileBackingStore(BackingStore):
# here we look for a non-colliding name
# this is potentially a race and so we abort after a few
# attempts
+ targetpath, ext = os.path.splitext(targetpath)
+
+ if filename_attempt_pattern.search(targetpath):
+ targetpath = filename_attempt_pattern.sub('', targetpath)
+
attempt += 1
if attempt > 9:
targetpath = "%s(%s).%s" % (targetpath, time.time(), ext)
break
- targetpath, ext = os.path.splitext(targetpath)
- targetpath = "%s(%s).%s" % (targetpath, attempt, ext)
+
+ targetpath = "%s(%s)%s" % (targetpath, attempt, ext)
path = self._translatePath(uid)
if subprocess.call(['cp', path, targetpath]):