aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustin Keogh <github.com@v6y.net>2022-03-03 13:09:00 +0000
committerGitHub <noreply@github.com>2022-03-03 05:09:00 -0800
commitacea8d7cfb60d9f9c33ed7662f72110531a54e6d (patch)
tree227a8d16b6718aa23771446fb324da63e6f098c2
parentf1d130902b4ae57f8223798a2472bfedea4203b8 (diff)
downloadhypervideo-pre-acea8d7cfb60d9f9c33ed7662f72110531a54e6d.tar.lz
hypervideo-pre-acea8d7cfb60d9f9c33ed7662f72110531a54e6d.tar.xz
hypervideo-pre-acea8d7cfb60d9f9c33ed7662f72110531a54e6d.zip
[utils] Fix file locking for AOSP (#2714)
Closes #2080, #2670 Authored by: jakeogh
-rw-r--r--yt_dlp/utils.py22
1 files changed, 16 insertions, 6 deletions
diff --git a/yt_dlp/utils.py b/yt_dlp/utils.py
index 1532210f3..8e9a7dbc8 100644
--- a/yt_dlp/utils.py
+++ b/yt_dlp/utils.py
@@ -2141,18 +2141,28 @@ if sys.platform == 'win32':
raise OSError('Unlocking file failed: %r' % ctypes.FormatError())
else:
- # Some platforms, such as Jython, is missing fcntl
try:
import fcntl
def _lock_file(f, exclusive, block):
- fcntl.flock(f,
- fcntl.LOCK_SH if not exclusive
- else fcntl.LOCK_EX if block
- else fcntl.LOCK_EX | fcntl.LOCK_NB)
+ try:
+ fcntl.flock(f,
+ fcntl.LOCK_SH if not exclusive
+ else fcntl.LOCK_EX if block
+ 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):
- fcntl.flock(f, fcntl.LOCK_UN)
+ try:
+ fcntl.flock(f, fcntl.LOCK_UN)
+ except OSError:
+ fcntl.lockf(f, fcntl.LOCK_UN)
except ImportError:
UNSUPPORTED_MSG = 'file locking is not supported on this platform'