]> jfr.im git - yt-dlp.git/commitdiff
[compat] Fix `shutils.move` in restricted ACL mode on BSD (#5309)
authorClosedPort22 <redacted>
Mon, 7 Nov 2022 15:24:30 +0000 (23:24 +0800)
committerGitHub <redacted>
Mon, 7 Nov 2022 15:24:30 +0000 (20:54 +0530)
Authored by: ClosedPort22, pukkandan

yt_dlp/compat/shutil.py [new file with mode: 0644]
yt_dlp/postprocessor/movefilesafterdownload.py

diff --git a/yt_dlp/compat/shutil.py b/yt_dlp/compat/shutil.py
new file mode 100644 (file)
index 0000000..23239d5
--- /dev/null
@@ -0,0 +1,30 @@
+# flake8: noqa: F405
+from shutil import *  # noqa: F403
+
+from .compat_utils import passthrough_module
+
+passthrough_module(__name__, 'shutil')
+del passthrough_module
+
+
+import sys
+
+if sys.platform.startswith('freebsd'):
+    import errno
+    import os
+    import shutil
+
+    # Workaround for PermissionError when using restricted ACL mode on FreeBSD
+    def copy2(src, dst, *args, **kwargs):
+        if os.path.isdir(dst):
+            dst = os.path.join(dst, os.path.basename(src))
+        shutil.copyfile(src, dst, *args, **kwargs)
+        try:
+            shutil.copystat(src, dst, *args, **kwargs)
+        except PermissionError as e:
+            if e.errno != getattr(errno, 'EPERM', None):
+                raise
+        return dst
+
+    def move(*args, copy_function=copy2, **kwargs):
+        return shutil.move(*args, copy_function=copy_function, **kwargs)
index 436d132272f36fa20a4fd058b9aea6c4993ba663..23b09248c28cdfe2287d0cc945d6ff18d9620eeb 100644 (file)
@@ -1,7 +1,7 @@
 import os
-import shutil
 
 from .common import PostProcessor
+from ..compat import shutil
 from ..utils import (
     PostProcessingError,
     decodeFilename,