Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed regression in file locking on some platforms.

Some platforms with os.name == 'posix' do not have the
fcntl module, e.g. AppEngine.

refs #19373.
  • Loading branch information...
commit 61fdb8d487f62e5b89b3bef9cb2b212dcec6d1e5 1 parent 8520e43
@smallcode smallcode authored timgraham committed
Showing with 25 additions and 25 deletions.
  1. +25 −25 django/core/files/locks.py
View
50 django/core/files/locks.py
@@ -85,29 +85,29 @@ def unlock(f):
overlapped = OVERLAPPED()
ret = UnlockFileEx(hfile, 0, 0, 0xFFFF0000, byref(overlapped))
return bool(ret)
+else:
+ try:
+ import fcntl
+ LOCK_SH = fcntl.LOCK_SH # shared lock
+ LOCK_NB = fcntl.LOCK_NB # non-blocking
+ LOCK_EX = fcntl.LOCK_EX
+ except (ImportError, AttributeError):
+ # File locking is not supported.
+ LOCK_EX = LOCK_SH = LOCK_NB = 0
+
+ # Dummy functions that don't do anything.
+ def lock(f, flags):
+ # File is not locked
+ return False
+
+ def unlock(f):
+ # File is unlocked
+ return True
+ else:
+ def lock(f, flags):
+ ret = fcntl.flock(_fd(f), flags)
+ return (ret == 0)
-elif os.name == 'posix':
- import fcntl
- LOCK_SH = fcntl.LOCK_SH # shared lock
- LOCK_NB = fcntl.LOCK_NB # non-blocking
- LOCK_EX = fcntl.LOCK_EX
-
- def lock(f, flags):
- ret = fcntl.flock(_fd(f), flags)
- return (ret == 0)
-
- def unlock(f):
- ret = fcntl.flock(_fd(f), fcntl.LOCK_UN)
- return (ret == 0)
-
-else: # File locking is not supported.
- LOCK_EX = LOCK_SH = LOCK_NB = 0
-
- # Dummy functions that don't do anything.
- def lock(f, flags):
- # File is not locked
- return False
-
- def unlock(f):
- # File is unlocked
- return True
+ def unlock(f):
+ ret = fcntl.flock(_fd(f), fcntl.LOCK_UN)
+ return (ret == 0)
Please sign in to comment.
Something went wrong with that request. Please try again.