
    obnF                     h   d Z ddlmZmZ ddlZddlZddlmZ ddlm	Z	 ddl
mZmZmZmZ ddlmZ dd	lmZ ej&                  rdd
lmZmZmZmZ ddlmZ eeeeegef   Z	 	 	 	 ddZ	 	 	 	 ddZ	 	 	 	 	 ddZ	 ddZ	 ddZ 	 ddZ!	 	 ddZ"	 	 	 ddZ#	 	 	 	 ddZ$	 	 	 	 ddZ%	 	 	 	 ddZ&d Z'd Z(y)z6Functions for copying resources *between* filesystem.
    )print_functionunicode_literalsN   )ResourceNotFound)	manage_fs)abspathcombinefrombasenormpath)is_thread_safe)Walker)CallableOptionalTextUnion)FSc           	      &    t        | |d||||      S )a@  Copy the contents of one filesystem to another.

    Arguments:
        src_fs (FS or str): Source filesystem (URL or instance).
        dst_fs (FS or str): Destination filesystem (URL or instance).
        walker (~fs.walk.Walker, optional): A walker object that will be
            used to scan for files in ``src_fs``. Set this if you only want
            to consider a sub-set of the resources in ``src_fs``.
        on_copy (callable): A function callback called after a single file copy
            is executed. Expected signature is ``(src_fs, src_path, dst_fs,
            dst_path)``.
        workers (int): Use `worker` threads to copy data, or ``0`` (default) for
            a single-threaded copy.
        preserve_time (bool): If `True`, try to preserve mtime of the
            resources (defaults to `False`).

    alwayspreserve_time)
copy_fs_ifsrc_fsdst_fswalkeron_copyworkersr   s         )/usr/lib/python3/dist-packages/fs/copy.pycopy_fsr      s     4 &'7-     c           	      Z    t        j                  dt               t        | |d||||      S )zCopy the contents of one filesystem to another, checking times.

    .. deprecated:: 2.5.0
       Use `~fs.copy.copy_fs_if` with ``condition="newer"`` instead.

    z7copy_fs_if_newer is deprecated. Use copy_fs_if instead.newerr   )warningswarnDeprecationWarningr   r   s         r   copy_fs_if_newerr&   7   s4     MMACU ' r    c                 *    t        | d|d|||||	      S )a  Copy the contents of one filesystem to another, depending on a condition.

    Arguments:
        src_fs (FS or str): Source filesystem (URL or instance).
        dst_fs (FS or str): Destination filesystem (URL or instance).
        condition (str): Name of the condition to check for each file.
        walker (~fs.walk.Walker, optional): A walker object that will be
            used to scan for files in ``src_fs``. Set this if you only want
            to consider a sub-set of the resources in ``src_fs``.
        on_copy (callable):A function callback called after a single file copy
            is executed. Expected signature is ``(src_fs, src_path, dst_fs,
            dst_path)``.
        workers (int): Use ``worker`` threads to copy data, or ``0`` (default)
            for a single-threaded copy.
        preserve_time (bool): If `True`, try to preserve mtime of the
            resources (defaults to `False`).

    See Also:
        `~fs.copy.copy_file_if` for the full list of supported values for the
        ``condition`` argument.

    /)r   r   r   r   copy_dir_if)r   r   	conditionr   r   r   r   s          r   r   r   N   s-    @ #
 
r    c                 &    t        | |||d|       y)a  Copy a file from one filesystem to another.

    If the destination exists, and is a file, it will be first truncated.

    Arguments:
        src_fs (FS or str): Source filesystem (instance or URL).
        src_path (str): Path to a file on the source filesystem.
        dst_fs (FS or str): Destination filesystem (instance or URL).
        dst_path (str): Path to a file on the destination filesystem.
        preserve_time (bool): If `True`, try to preserve mtime of the
            resource (defaults to `False`).

    r   r   N)copy_file_ifr   src_pathr   dst_pathr   s        r   	copy_filer1   {   s    * &(HMr    c                 X    t        j                  dt               t        | |||d|      S )zCopy a file from one filesystem to another, checking times.

    .. deprecated:: 2.5.0
       Use `~fs.copy.copy_file_if` with ``condition="newer"`` instead.

    z;copy_file_if_newer is deprecated. Use copy_file_if instead.r"   r   )r#   r$   r%   r-   r.   s        r   copy_file_if_newerr3      s2     MME &(G= r    c           
          t        | d      5 }t        |d      5 }t        |||||      }|rt        |||||d       |cddd       cddd       S # 1 sw Y   nxY w	 ddd       y# 1 sw Y   yxY w)a  Copy a file from one filesystem to another, depending on a condition.

    Depending on the value of ``condition``, certain requirements must
    be fulfilled for a file to be copied to ``dst_fs``. The following
    values are supported:

    ``"always"``
        The source file is always copied.
    ``"newer"``
        The last modification time of the source file must be newer than that
        of the destination file. If either file has no modification time, the
        copy is performed always.
    ``"older"``
        The last modification time of the source file must be older than that
        of the destination file. If either file has no modification time, the
        copy is performed always.
    ``"exists"``
        The source file is only copied if a file of the same path already
        exists in ``dst_fs``.
    ``"not_exists"``
        The source file is only copied if no file of the same path already
        exists in ``dst_fs``.

    Arguments:
        src_fs (FS or str): Source filesystem (instance or URL).
        src_path (str): Path to a file on the source filesystem.
        dst_fs (FS or str): Destination filesystem (instance or URL).
        dst_path (str): Path to a file on the destination filesystem.
        condition (str): Name of the condition to check for each file.
        preserve_time (bool): If `True`, try to preserve mtime of the
            resource (defaults to `False`).

    Returns:
        bool: `True` if the file copy was executed, `False` otherwise.

    F	writeableTcreate)r   lockN)r   _copy_is_necessarycopy_file_internal)	r   r/   r   r0   r+   r   _src_fs_dst_fsdo_copys	            r   r-   r-      s    Z 
6U	+ wvd+ 	w(7HiG ""/ 	 	 	 	 	  s"   A)$A 	A)A	A))A2c                 
     u r j                  d       y fd}|r: j                         5  j                         5   |        ddd       ddd       y |        y# 1 sw Y   xY w# 1 sw Y   yxY w)a  Copy a file at low level, without calling `manage_fs` or locking.

    If the destination exists, and is a file, it will be first truncated.

    This method exists to optimize copying in loops. In general you
    should prefer `copy_file`.

    Arguments:
        src_fs (FS): Source filesystem.
        src_path (str): Path to a file on the source filesystem.
        dst_fs (FS): Destination filesystem.
        dst_path (str): Path to a file on the destination filesystem.
        preserve_time (bool): If `True`, try to preserve mtime of the
            resource (defaults to `False`).
        lock (bool): Lock both filesystems before copying.

    T)	overwriter   Nc                  .   j                        r.j                  d      5 } j                  |        d d d        n,j                        5 }j                  |       d d d        rt	               y y # 1 sw Y   xY w# 1 sw Y   'xY w)Nw)
hassyspathopenbindownloaduploadcopy_modified_time)
write_file	read_filer   r0   r   r   r/   s     r   _copy_lockedz(copy_file_internal.<locals>._copy_locked
  s    X&#. 6**56 6 ) 3Yh	23 vxB 6 63 3s   A?B?BB)copyr9   )r   r/   r   r0   r   r9   rJ   s   `````  r   r;   r;      s    4  	Hh$mT	C 	C [[] 	FKKM 	N	 	 	 		 	 	 	s#   A9A-A9-A6	2A99Bc                    |xs
 t               }t        |       5 }t        |d      5 }|j                         5  |j                         5  |j                  |d       |j	                  ||      D ])  }|j                  t        |t        ||            d       + 	 ddd       ddd       ddd       ddd       y# 1 sw Y   "xY w# 1 sw Y   &xY w# 1 sw Y   *xY w# 1 sw Y   yxY w)ap  Copy directories (but not files) from ``src_fs`` to ``dst_fs``.

    Arguments:
        src_fs (FS or str): Source filesystem (instance or URL).
        dst_fs (FS or str): Destination filesystem (instance or URL).
        walker (~fs.walk.Walker, optional): A walker object that will be
            used to scan for files in ``src_fs``. Set this if you only
            want to consider a sub-set of the resources in ``src_fs``.
        src_root (str): Path of the base directory to consider as the root
            of the tree structure to copy.
        dst_root (str): Path to the target root of the tree structure.

    Tr7   )recreateN)r   r   r9   makedirsdirsmakedirr	   r
   )r   r   r   src_rootdst_rootr<   r=   dir_paths           r   copy_structurerT     s    * vxF	6	 gvd+ 	w    D 9 &GX > HOO(8X*FGRV $  	    	 	 sR   C"CC

AB>	C
%C-C">CC

CCC	C""C+c                 ,    t        | |||d||||	       y)a  Copy a directory from one filesystem to another.

    Arguments:
        src_fs (FS or str): Source filesystem (instance or URL).
        src_path (str): Path to a directory on the source filesystem.
        dst_fs (FS or str): Destination filesystem (instance or URL).
        dst_path (str): Path to a directory on the destination filesystem.
        walker (~fs.walk.Walker, optional): A walker object that will be
            used to scan for files in ``src_fs``. Set this if you only
            want to consider a sub-set of the resources in ``src_fs``.
        on_copy (callable, optional):  A function callback called after
            a single file copy is executed. Expected signature is
            ``(src_fs, src_path, dst_fs, dst_path)``.
        workers (int): Use ``worker`` threads to copy data, or ``0`` (default) for
            a single-threaded copy.
        preserve_time (bool): If `True`, try to preserve mtime of the
            resources (defaults to `False`).

    r   r   Nr)   r   r/   r   r0   r   r   r   r   s           r   copy_dirrW   <  s'    < #
r    c                 `    t        j                  dt               t        | |||d||||	       y)zCopy a directory from one filesystem to another, checking times.

    .. deprecated:: 2.5.0
       Use `~fs.copy.copy_dir_if` with ``condition="newer"`` instead.

    z9copy_dir_if_newer is deprecated. Use copy_dir_if instead.r"   r   N)r#   r$   r%   r*   rV   s           r   copy_dir_if_newerrY   g  s;    " MMCEW #
r    c	                    |xs d }|xs
 t               }t        t        |            }	t        t        |            }
ddlm} t        | ||||       t        | d      5 }t        |d      5 }|j                         5  |j                         5  t        ||      } ||r|nd|	      5 }|j                  ||	      D ]G  }t        |
t        |	|            }t        |||||      s)|j                  ||||        |||||       I 	 d
d
d
       d
d
d
       d
d
d
       d
d
d
       d
d
d
       y
# 1 sw Y   *xY w# 1 sw Y   .xY w# 1 sw Y   2xY w# 1 sw Y   6xY w# 1 sw Y   y
xY w)a  Copy a directory from one filesystem to another, depending on a condition.

    Arguments:
        src_fs (FS or str): Source filesystem (instance or URL).
        src_path (str): Path to a directory on the source filesystem.
        dst_fs (FS or str): Destination filesystem (instance or URL).
        dst_path (str): Path to a directory on the destination filesystem.
        condition (str): Name of the condition to check for each file.
        walker (~fs.walk.Walker, optional): A walker object that will be
            used to scan for files in ``src_fs``. Set this if you only want
            to consider a sub-set of the resources in ``src_fs``.
        on_copy (callable):A function callback called after a single file copy
            is executed. Expected signature is ``(src_fs, src_path, dst_fs,
            dst_path)``.
        workers (int): Use ``worker`` threads to copy data, or ``0`` (default) for
            a single-threaded copy.
        preserve_time (bool): If `True`, try to preserve mtime of the
            resources (defaults to `False`).

    See Also:
        `~fs.copy.copy_file_if` for the full list of supported values for the
        ``condition`` argument.

    c                       y )N )argss    r   <lambda>zcopy_dir_if.<locals>.<lambda>  s    r    r   )CopierFr5   Tr7   r   )num_workersr   N)r   r   r   _bulkr_   rT   r   r9   r   filesr	   r
   r:   rK   )r   r/   r   r0   r+   r   r   r   r   	_src_path	_dst_pathr_   r<   r=   _thread_safecopierrS   	copy_paths                     r   r*   r*     s   H -,GvxF*+I*+I6668X>	6U	+ Gw	t9 G	\\^ 	GW\\^ 	G)'7;L'3G- 	G &Wi @ GH '	8Ix3P QI)7Iy GXw	J7IFG	G	G 	GG G G
	G 	G	G 	G 	G 	GG G G Gsr    E".E?E
D>	+;D2'!D2	D>	E
E!E"2D;7D>	>EE

EEE	E""E+c                    |dk(  ry|dk(  r4	 | j                  |      }|j                  |      }|d u xs |d u xs ||kD  S |dk(  r4	 | j                  |      }|j                  |      }|d u xs |d u xs ||k  S |dk(  r|j                  |      S |dk(  r|j                  |       S t        dj	                  |            # t        $ r Y yw xY w# t        $ r Y yw xY w)Nr   Tr"   olderexists
not_existsz!{} is not a valid copy condition.)getmodifiedr   rj   
ValueErrorformat)r   r/   r   r0   r+   src_modifieddst_modifieds          r   r:   r:     s0    H	g	
	!--h7L!--h7L
 $ /4'/,. 
g	
	!--h7L!--h7L
 $ /4'/,. 
h	}}X&&	l	"==*** <CCINOO;   		   		s#   "C  "C  	CC	CCc                 @   d}t        | d      5 }t        |d      5 }|j                  ||      }|j                  j                  di       }i }	dD ]  }
|
|v s||
   |	|
<    |j	                  |d|	i       ddd       ddd       y# 1 sw Y   xY w# 1 sw Y   yxY w)	ac  Copy modified time metadata from one file to another.

    Arguments:
        src_fs (FS or str): Source filesystem (instance or URL).
        src_path (str): Path to a directory on the source filesystem.
        dst_fs (FS or str): Destination filesystem (instance or URL).
        dst_path (str): Path to a directory on the destination filesystem.

    )detailsFr5   Tr7   rr   )metadata_changedmodifiedN)r   getinforawgetsetinfo)r   r/   r   r0   
namespacesr<   r=   src_metasrc_detailsdst_detailsvalues              r   rG   rG     s      J	6U	+ @wvd+ 	@wx<H",,**9b9KK9 <K')4U);K&< OOHy+&>?	@@ @	@ 	@@ @s(   B:BB7BB	BB)NNr   F)r   NNr   F)F)FF)Nr(   r(   ))__doc__
__future__r   r   typingr#   errorsr   openerr   pathr   r	   r
   r   toolsr   walkr   TYPE_CHECKINGr   r   r   r   baser   object_OnCopyr   r&   r   r1   r3   r-   r;   rT   rW   rY   r*   r:   rG   r\   r    r   <module>r      s   8   $  6 6 ! 	66D"d+V34G D 4 *d > : ;F 	/j J (` N ;G|-P`@r    