summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoeri Bekker <joeri@maykinmedia.nl>2013-02-24 14:05:29 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2013-02-24 14:21:40 +0100
commitb9cc61021a0db1e5b41e61d3e53180e4fc618f9c (patch)
treeb95ca692733ecde6e5b5261bd5acb89fdf947aaa
parent7106a1e594dc28108e7e4f83af3ffb25289d3bb0 (diff)
Fixed #9084 - Best approach for an OS to atomically rename the session file.
-rw-r--r--django/contrib/sessions/backends/file.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/django/contrib/sessions/backends/file.py b/django/contrib/sessions/backends/file.py
index 7d933c678a..9588680fea 100644
--- a/django/contrib/sessions/backends/file.py
+++ b/django/contrib/sessions/backends/file.py
@@ -1,6 +1,7 @@
import datetime
import errno
import os
+import shutil
import tempfile
from django.conf import settings
@@ -147,7 +148,11 @@ class SessionStore(SessionBase):
os.write(output_file_fd, self.encode(session_data).encode())
finally:
os.close(output_file_fd)
- os.rename(output_file_name, session_file_name)
+
+ # This will atomically rename the file (os.rename) if the OS
+ # supports it. Otherwise this will result in a shutil.copy2
+ # and os.unlink (for example on Windows). See #9084.
+ shutil.move(output_file_name, session_file_name)
renamed = True
finally:
if not renamed: