diff options
author | Benjamin Saller <bcsaller@objectrealms.net> | 2007-06-24 17:54:16 (GMT) |
---|---|---|
committer | Benjamin Saller <bcsaller@objectrealms.net> | 2007-06-24 17:54:16 (GMT) |
commit | e7ca4d9a939391cacf842742aea59fa1bd47e6e6 (patch) | |
tree | 81e4d9a59302afca72b866576b97953d43052057 /src/olpc/datastore/backingstore.py | |
parent | 84fdcc41b9d4663fd375c8af552930c197bd450a (diff) |
honor mimetype when available
Diffstat (limited to 'src/olpc/datastore/backingstore.py')
-rw-r--r-- | src/olpc/datastore/backingstore.py | 12 |
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]): |