
    ob                         d Z ddlmZmZ ddlZddlmZ ddlmZ ddl	m
Z
 ddl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 ddlmZ d Z	 	 	 	 ddZddedfdZy)a  Function for *mirroring* a filesystem.

Mirroring will create a copy of a source filesystem on a destination
filesystem. If there are no files on the destination, then mirroring
is simply a straight copy. If there are any files or directories on the
destination they may be deleted or modified to match the source.

In order to avoid redundant copying of files, `mirror` can compare
timestamps, and only copy files with a newer modified date. This
timestamp comparison is only done if the file sizes are different.

This scheme will work if you have mirrored a directory previously, and
you would like to copy any changes. Otherwise you should set the
``copy_if_newer`` parameter to `False` to guarantee an exact copy, at
the expense of potentially copying extra files.

    )print_functionunicode_literalsN   )Copier)copy_file_internal)ResourceNotFound	manage_fs)is_thread_safe)Walker)CallableOptionalTextUnion)FS)Infoc                     | j                   |j                   k7  ry| j                  }|j                  }|du xs |du xs ||kD  S )zCompare two `Info` objects to see if they should be copied.

    Returns:
        bool: `True` if the `Info` are different in size or mtime.

    TN)sizemodified)info1info2date1date2s       +/usr/lib/python3/dist-packages/fs/mirror.py_comparer   %   sE     zzUZZNNENNED=:ETM:UU]:    TFc                      fd}fd} |       5 } |       5 }	t        ||	      }
t        |
r|nd|      5 }|j                         5  |	j                         5  t        ||	|||j                  |       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)aY  Mirror files / directories from one filesystem to another.

    Mirroring a filesystem will create an exact copy of ``src_fs`` on
    ``dst_fs``, by removing any files / directories on the destination
    that aren't on the source, and copying files that aren't.

    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): An optional walker instance.
        copy_if_newer (bool): Only copy newer files (the default).
        workers (int): Number of worker threads used
            (0 for single threaded). Set to a relatively low number
            for network filesystems, 4 would be a good start.
        preserve_time (bool): If `True`, try to preserve mtime of the
            resources (defaults to `False`).

    c                      t         d      S )NF)	writeabler	   )src_fss   r   srczmirror.<locals>.srcR   s    511r   c                      t         d      S )NT)creater	   )dst_fss   r   dstzmirror.<locals>.dstU   s    --r   r   )num_workerspreserve_time)walkercopy_if_newer	copy_filer'   N)r   r   lock_mirrorcopy)r    r$   r(   r)   workersr'   r!   r%   _src_fs_dst_fs_thread_safecopiers   ``          r   mirrorr3   6   s    82. 
 '35 G%gw7#/Qm
 	  !"/$kk"/ 	  
   	 	   si   CCB9B-	B!8B-	 B9CC!B*&B-	-B62B99C>CC	
CCc           	      n   |xs
 t               }|j                  | dg      }|D ]e  \  }}}		 |j                  |dg      D 
ci c]  }
|
j                  |
 }}
|	D ]j  }|j                  |      }|j                  |j                  d       }|-|j                  r|j                  |       n|rt        ||      s_ || ||||       l |D ]c  }|j                  |      }|j                  |j                  d       }||j                  r?|j                  |       Q|j                  |d       e |s|j                         \  }}
|
j                  |      }|
j                  r|j                  |       n|j                  |       |rVh y c c}
w # t        $ r |j                  |       i }Y Yw xY w)Ndetails)
namespacesT)recreate)r   walkscandirnamer   makedir	make_pathpopis_dir
removetreer   removepopitem)r    r$   r(   r)   r*   r'   r8   pathdirsfilesinfor%   _file_pathdst_file_dirdst_dir_s                     r   r,   r,   h   s    vxF;;v9+;6D! +%dE	,2NN4YKN,X$(		4C   	CEOOD)Ewwuzz40H#??%%e, %XeX-F feVUMB	C  
	5DNN4(Eggdii.G"~~MM%( ut4
	5 kkmGAtNN4(E{{!!%(e$ K+%   	NN4 C	s#   FFFFF43F4)NTr   F)__doc__
__future__r   r   typing_bulkr   r-   r   errorsr   openerr
   toolsr   r8   r   TYPE_CHECKINGr   r   r   r   baser   rE   r   r   r3   r,    r   r   <module>rV      se   $ 8   $ $  ! 	66;( /j  6%r   