diff options
| author | smallcode <14190635@qq.com> | 2014-03-17 18:46:58 +0800 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-03-18 10:35:22 -0400 |
| commit | 61fdb8d487f62e5b89b3bef9cb2b212dcec6d1e5 (patch) | |
| tree | de36af5844b521a0182975fbc5de30ab94faa397 | |
| parent | 8520e43e138f518b5962c00f05e17dab70a407da (diff) | |
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.
| -rwxr-xr-x | django/core/files/locks.py | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/django/core/files/locks.py b/django/core/files/locks.py index bcb218a036..8f7cef0a3e 100755 --- a/django/core/files/locks.py +++ b/django/core/files/locks.py @@ -85,29 +85,29 @@ if os.name == 'nt': 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 -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 + # Dummy functions that don't do anything. + def lock(f, flags): + # File is not locked + return False - 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 + else: + def lock(f, flags): + ret = fcntl.flock(_fd(f), flags) + return (ret == 0) - def unlock(f): - # File is unlocked - return True + def unlock(f): + ret = fcntl.flock(_fd(f), fcntl.LOCK_UN) + return (ret == 0) |
