reverted use of os.ftruncate in languages because not portable on windows but removed unlocking when locked shared, should be tested

This commit is contained in:
Massimo DiPierro
2012-01-13 23:00:16 -06:00
parent 1af865b748
commit ade52fe8f8
2 changed files with 6 additions and 13 deletions

View File

@@ -1 +1 @@
Version 1.99.4 (2012-01-12 22:51:51) stable
Version 1.99.4 (2012-01-13 23:00:13) stable

View File

@@ -37,18 +37,11 @@ regex_language = \
re.compile('^[a-zA-Z]{2}(\-[a-zA-Z]{2})?(\-[a-zA-Z]+)?$')
class FilenoFile():
""" Class to wrap a file descriptor like a file object does. """
def __init__(self, fd):
self.fd = fd
def fileno(self):
return self.fd
def read_dict_aux(filename):
fp = open(filename, 'r')
portalocker.lock(fp, portalocker.LOCK_SH)
lang_text = fp.read().replace('\r\n', '\n')
# needed? portalocker.unlock(fp)
fp.close()
if not lang_text.strip():
return {}
@@ -98,20 +91,20 @@ def utf8_repr(s):
def write_dict(filename, contents):
try:
fd = os.open(filename, os.O_RDWR | os.O_CREAT)
fp = open(filename, 'w')
except (IOError, OSError):
if not is_gae:
logging.warning('Unable to write to file %s' % filename)
return
portalocker.lock(FilenoFile(fd), portalocker.LOCK_EX)
os.ftruncate(fd, 0)
fp = os.fdopen(fd, 'w')
portalocker.lock(fp, portalocker.LOCK_EX)
fp.write('# coding: utf8\n{\n')
for key in sorted(contents):
fp.write('%s: %s,\n' % (utf8_repr(key), utf8_repr(contents[key])))
fp.write('}\n')
portalocker.unlock(fp)
fp.close()
class lazyT(object):
"""