Attachment 'user.patch'

Download

   1 diff -r 172146fe48a2 MoinMoin/user.py
   2 --- a/MoinMoin/user.py	Tue May 11 23:08:11 2010 +0200
   3 +++ b/MoinMoin/user.py	Sun May 16 19:01:30 2010 +0200
   4 @@ -19,12 +19,12 @@
   5      @license: GNU GPL, see COPYING for details.
   6  """
   7  
   8 -import os, time, codecs, base64
   9 +import os, time, codecs, base64, tempfile
  10  
  11  from MoinMoin.support.python_compatibility import hash_new, hmac_new
  12  
  13  from MoinMoin import config, caching, wikiutil, i18n, events
  14 -from MoinMoin.util import timefuncs, random_string
  15 +from MoinMoin.util import filesys, timefuncs, random_string
  16  from MoinMoin.wikiutil import url_quote_plus
  17  
  18  
  19 @@ -542,11 +542,8 @@
  20              os.makedirs(user_dir)
  21  
  22          self.last_saved = str(time.time())
  23 -
  24 -        # !!! should write to a temp file here to avoid race conditions,
  25 -        # or even better, use locking
  26 -
  27 -        data = codecs.open(self.__filename(), "w", config.charset)
  28 +        fd, _tmp_filename = tempfile.mkstemp('.tmp', self.__filename(), self._cfg.user_dir)
  29 +        data = codecs.open(_tmp_filename, "w", config.charset)
  30          data.write("# Data saved '%s' for id '%s'\n" % (
  31              time.strftime(self._cfg.datetime_fmt, time.localtime(time.time())),
  32              self.id))
  33 @@ -565,6 +562,7 @@
  34              line = line.replace('\n', ' ').replace('\r', ' ') # no lineseps
  35              data.write(line + '\n')
  36          data.close()
  37 +        filesys.rename(_tmp_filename, self.__filename())
  38  
  39          arena = 'user'
  40          key = 'name2id'

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2010-05-16 17:02:04, 1.4 KB) [[attachment:user.patch]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.