There was an error while loading. Please reload this page.
1 parent 7106a1e commit b9cc610Copy full SHA for b9cc610
django/contrib/sessions/backends/file.py
@@ -1,6 +1,7 @@
1
import datetime
2
import errno
3
import os
4
+import shutil
5
import tempfile
6
7
from django.conf import settings
@@ -147,7 +148,11 @@ def save(self, must_create=False):
147
148
os.write(output_file_fd, self.encode(session_data).encode())
149
finally:
150
os.close(output_file_fd)
- os.rename(output_file_name, session_file_name)
151
+
152
+ # This will atomically rename the file (os.rename) if the OS
153
+ # supports it. Otherwise this will result in a shutil.copy2
154
+ # and os.unlink (for example on Windows). See #9084.
155
+ shutil.move(output_file_name, session_file_name)
156
renamed = True
157
158
if not renamed:
0 commit comments