Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #9084 - Best approach for an OS to atomically rename the sessio…

…n file.
  • Loading branch information...
commit b9cc61021a0db1e5b41e61d3e53180e4fc618f9c 1 parent 7106a1e
Joeri Bekker joeribekker authored aaugustin committed
Showing with 6 additions and 1 deletion.
  1. +6 −1 django/contrib/sessions/backends/file.py
7 django/contrib/sessions/backends/file.py
View
@@ -1,6 +1,7 @@
import datetime
import errno
import os
+import shutil
import tempfile
from django.conf import settings
@@ -147,7 +148,11 @@ def save(self, must_create=False):
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:
Please sign in to comment.
Something went wrong with that request. Please try again.