mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-26 02:55:17 +00:00
[utils] Fix file locking for AOSP (#2714)
Closes #2080, #2670 Authored by: jakeogh
This commit is contained in:
parent
f1d130902b
commit
acea8d7cfb
1 changed files with 16 additions and 6 deletions
|
@ -2141,18 +2141,28 @@ def _unlock_file(f):
|
||||||
raise OSError('Unlocking file failed: %r' % ctypes.FormatError())
|
raise OSError('Unlocking file failed: %r' % ctypes.FormatError())
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Some platforms, such as Jython, is missing fcntl
|
|
||||||
try:
|
try:
|
||||||
import fcntl
|
import fcntl
|
||||||
|
|
||||||
def _lock_file(f, exclusive, block):
|
def _lock_file(f, exclusive, block):
|
||||||
|
try:
|
||||||
fcntl.flock(f,
|
fcntl.flock(f,
|
||||||
fcntl.LOCK_SH if not exclusive
|
fcntl.LOCK_SH if not exclusive
|
||||||
else fcntl.LOCK_EX if block
|
else fcntl.LOCK_EX if block
|
||||||
else fcntl.LOCK_EX | fcntl.LOCK_NB)
|
else fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||||
|
except BlockingIOError:
|
||||||
|
raise
|
||||||
|
except OSError: # AOSP does not have flock()
|
||||||
|
fcntl.lockf(f,
|
||||||
|
fcntl.LOCK_SH if not exclusive
|
||||||
|
else fcntl.LOCK_EX if block
|
||||||
|
else fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||||
|
|
||||||
def _unlock_file(f):
|
def _unlock_file(f):
|
||||||
|
try:
|
||||||
fcntl.flock(f, fcntl.LOCK_UN)
|
fcntl.flock(f, fcntl.LOCK_UN)
|
||||||
|
except OSError:
|
||||||
|
fcntl.lockf(f, fcntl.LOCK_UN)
|
||||||
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
UNSUPPORTED_MSG = 'file locking is not supported on this platform'
|
UNSUPPORTED_MSG = 'file locking is not supported on this platform'
|
||||||
|
|
Loading…
Reference in a new issue