summaryrefslogtreecommitdiffstats
path: root/yt_dlp/compat/shutil.py
blob: 23239d5ce84a7d73de6320968bb63a3626ea26eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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)