Skip to content

Commit

Permalink
Fixed regression in file locking on some platforms.
Browse files Browse the repository at this point in the history
Some platforms with os.name == 'posix' do not have the
fcntl module, e.g. AppEngine.

refs #19373.
  • Loading branch information
smallcode authored and timgraham committed Mar 18, 2014
1 parent 8520e43 commit 61fdb8d
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions django/core/files/locks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 61fdb8d

Please sign in to comment.