Changeset 8707
- Timestamp:
- 08/29/08 12:32:21 (3 months ago)
- Files:
-
- django/trunk/AUTHORS (modified) (1 diff)
- django/trunk/django/contrib/sessions/backends/file.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/AUTHORS
r8688 r8707 364 364 sloonz <simon.lipp@insa-lyon.fr> 365 365 SmileyChris <smileychris@gmail.com> 366 Warren Smith <warren@wandrsmith.net>367 366 smurf@smurf.noris.de 368 367 Vsevolod Solovyov django/trunk/django/contrib/sessions/backends/file.py
r8688 r8707 6 6 from django.contrib.sessions.backends.base import SessionBase, CreateError 7 7 from django.core.exceptions import SuspiciousOperation, ImproperlyConfigured 8 from django.core.files import locks9 8 10 IO_LOCK_SUFFIX = "_iolock"11 9 12 10 class SessionStore(SessionBase): … … 45 43 return os.path.join(self.storage_path, self.file_prefix + session_key) 46 44 47 def _key_to_io_lock_file(self, session_key=None):48 """49 Get the I/O lock file associated with this session key.50 """51 return self._key_to_file(session_key) + IO_LOCK_SUFFIX52 53 45 def load(self): 54 46 session_data = {} 55 47 try: 56 # Open and acquire a shared lock on the I/O lock file before 57 # attempting to read the session file. This makes us wait to read 58 # the session file until another thread or process is finished 59 # writing it. 60 lock_path = self._key_to_io_lock_file() 61 io_lock_file = open(lock_path, "rb") 62 locks.lock(io_lock_file, locks.LOCK_SH) 48 session_file = open(self._key_to_file(), "rb") 63 49 try: 64 session_file = open(self._key_to_file(), "rb")65 50 try: 66 try: 67 session_data = self.decode(session_file.read()) 68 except (EOFError, SuspiciousOperation): 69 self.create() 70 finally: 71 session_file.close() 51 session_data = self.decode(session_file.read()) 52 except (EOFError, SuspiciousOperation): 53 self.create() 72 54 finally: 73 locks.unlock(io_lock_file) 74 io_lock_file.close() 75 os.unlink(lock_path) 55 session_file.close() 76 56 except IOError: 77 57 pass … … 97 77 session_data = self._get_session(no_load=must_create) 98 78 try: 99 # Open and acquire an exclusive lock on the I/O lock file before 100 # attempting to write the session file. This makes other threads 101 # or processes wait to read or write the session file until we are 102 # finished writing it. 103 lock_path = self._key_to_io_lock_file() 104 io_lock_file = open(lock_path, "wb") 105 locks.lock(io_lock_file, locks.LOCK_EX) 79 fd = os.open(self._key_to_file(self.session_key), flags) 106 80 try: 107 fd = os.open(self._key_to_file(self.session_key), flags) 108 try: 109 os.write(fd, self.encode(session_data)) 110 finally: 111 os.close(fd) 81 os.write(fd, self.encode(session_data)) 112 82 finally: 113 locks.unlock(io_lock_file) 114 io_lock_file.close() 115 os.unlink(lock_path) 83 os.close(fd) 116 84 except OSError, e: 117 85 if must_create and e.errno == errno.EEXIST:
