AlkantarClanX12

Your IP : 3.141.2.191


Current Path : /proc/self/root/lib/python3.6/site-packages/slip/util/__pycache__/
Upload File :
Current File : //proc/self/root/lib/python3.6/site-packages/slip/util/__pycache__/files.cpython-36.pyc

3

�uAc��@s�dZddlmZdee�kr eZdddddgZdd	lZdd	l	Z	dd	l
Z
dd	lZdd	lZd
Z
dd�Zgfd
d�Zdd�Zddd�Zddd�Zddd�Zddd�Zd	S)z=This module contains helper functions for dealing with files.�)�absolute_import�xrange�
issamefile�linkfile�copyfile�linkorcopyfile�overwrite_safelyNicCs"tj|�}tj|�}tjj||�S)N)�os�stat�path�samestat)�path1�path2�s1�s2�r�/usr/lib/python3.6/files.py�_issamefile+s

rcCs0|dkrt}y
t||�S|k
r*dSXdS)zECheck whether two paths point to the same file (i.e. are hardlinked).TFN)�	Exceptionr)r
r�catch_stat_exceptionsrrrr2s
cCs�t||td�rdStjj|�}tjj|�}tjj|�}d}xpttj	�D]b}tj
|tj|d�}ytj||�Wn2tk
r�}z|j
t
jkr�n�WYdd}~XqFXd}PqFW|r�tj||�dS)zUHardlink srcpath to dstpath.

    Attempt to atomically replace dstpath if it exists.)rNF)�prefix�dirT)r�OSErrorr	r�abspath�dirname�basename�range�tempfile�TMP_MAX�mktemp�extsep�link�errno�EEXIST�rename)�srcpath�dstpath�dstdname�dstbnameZ
hardlinked�attempt�_dsttmp�errrr>s$Tc
Cs8t||td�rdStjj|�}tjj|�}tjj|�}t|d�}tj	|tjj
|dd�}tj|�}|r�ytj|�}Wntk
r�YnXtj|j
�tj|j��d}	xP|	dkr�|jt�}	y|j|	�Wq�|j�|j�tj|j��Yq�Xq�W|j�|j�tj|j|�|�r4tj�dk�r4tj|�dS)z�Copy srcpath to dstpath.

    Abort operation if e.g. not enough space is available.  Attempt to
    atomically replace dstpath if it exists.)rN�rbF)rr�delete�r)rrr	rrrr�openrZNamedTemporaryFiler r
�fchmod�fileno�S_IMODE�st_mode�read�	BLOCKSIZE�write�close�unlink�namer$�selinux�is_selinux_enabled�
restorecon)
r%r&�copy_mode_from_dst�run_restoreconr'r(ZsrcfileZ
dsttmpfile�s�datarrrr_s<



cCs^yt||�dStk
rJ}z |jtjtjtjfkr:�nWYdd}~XnXt||||�dS)ztFirst attempt to hardlink srcpath to dstpath, if hardlinking isn't
    possible, attempt copying srcpath to dstpath.N)rrr"ZEMLINKZEPERMZEXDEVr)r%r&r=r>r+rrrr�s
Fc
Cs�tjj|�}tjj|�}d}d}|r6tj�dkr6d}n^y&tj|�\}}|dkrZtd|��Wn6tk
r�}	z|	j	t	j
kr�d}n�WYdd}	~	XnX|s�tj||�|r�tj|�n�d}
xtt
tj�D]f}tj|tj|d�}ytj||�Wn6tk
�r"}	z|	j	t	jk�rwĂWYdd}	~	Xq�X|}
Pq�W|
dk�rDtt	jd��|�r^|�r^tj|
|�ytj|
|�Wntj|
��YnX|�r�tj|�dS)zpCreate a symlink, optionally replacing dstpath atomically, optionally
    setting or preserving SELinux context.FNrzgetfilecon(%r) failedT)rrz/No suitable temporary symlink could be created.)r	rrrr:r;Zlgetfilecon�RuntimeErrorrr"�ENOENT�symlinkr<rrrrr r#�IOErrorZlsetfileconr$�remove)
r%r&�force�preserve_contextr'r(r>�ctx�retr+Zdsttmpr)r*rrr�symlink_atomically�sV

rJcCs~tjj|�}tjj|�}tjj|�}d}d}d}	tjj|�}
|rPtj�dkrPd}z�tj	|tjj
|d�\}}	|
r�tj|�}|r�tj||j
|j�|r�tj|tj|j��|r�tj|�\}}
|dkr�td|��tj|d�}d}|j|�|j�d}tj|	|�|�r$|
�rtj||
�n
tj|�Wd|�r8|j�n|�rHtj|�|	�rxtjj|	��rxytj|	�WnYnXXdS)z�Safely overwrite a file by creating a temporary file in the same
    directory, writing it, moving it over the original file, eventually
    preserving file mode, SELinux context and ownership.NrF)rrzgetfilecon(%r) failed�w)r	r�realpathrr�existsr:r;rZmkstempr r
�fchown�st_uid�st_gidr0r2r3Z
getfileconrA�fdopenr6r7r$Z
setfileconr<�isfiler8)rZcontentZ
preserve_moderGZpreserve_ownershipZdir_�base�fd�fZtmpnamerMr?rIrHrrrr�sR



)TT)TT)FT)TTT)�__doc__Z
__future__rr�__builtins__rr�__all__r	r:rr"r
r5rrrrrrJrrrrr�<module>s&!
5

?