HEX
Server: Apache
System: Linux srv1.prosuiteplus.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: prosuiteplus (1001)
PHP: 8.3.20
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/slip/util/__pycache__/files.cpython-38.pyc
U

�Y��@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"t�|�}t�|�}tj�||�S)N)�os�stat�path�samestat)�path1�path2�s1�s2�r�1/usr/lib/python3/dist-packages/slip/util/files.py�_issamefile+s

rcCs4|dkrt}zt||�WS|k
r.YdSXdS)zECheck whether two paths point to the same file (i.e. are hardlinked).TFN)�	Exceptionr)r
r�catch_stat_exceptionsrrrr2scCs�t||td�rdStj�|�}tj�|�}tj�|�}d}ttj	�D]d}tj
|tj|d�}zt�||�Wn2tk
r�}z|j
t
jkr�n�W5d}~XYqDXd}q�qD|r�t�||�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
Cs4t||td�rdStj�|�}tj�|�}tj�|�}t|d�}tj	|tjj
|dd�}t�|�}|r�zt�|�}Wntk
r�YnXt�|�
�t�|j��d}	|	dkr�|�t�}	z|�|	�Wq�|��|��t�|j��Yq�Xq�|��|��t�|j|�|�r0t��dk�r0t�|�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_sB

�


c
Cs`zt||�WdStk
rL}z|jtjtjtjfkr<�nW5d}~XYnXt||||�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�tj�|�}tj�|�}d}d}|r6t��dkr6d}n^z&t�|�\}}|dkrZtd|��Wn6tk
r�}	z|	j	t	j
kr�d}n�W5d}	~	XYnX|s�t�||�|r�t�|�n�d}
t
tj�D]p}tj|tj|d�}zt�||�Wn<tk
�r&}	z|	j	t	jk�rWY�q‚W5d}	~	XYq�X|}
�q4q�|
dk�rJtt	jd��|�rb|�sbt�|
|�zt�|
|�Wnt�|
��YnX|�r�t�|�dS)zpCreate a symlink, optionally replacing dstpath atomically, optionally
    setting or preserving SELinux context.FNr�getfilecon(%r) failedTrz/No suitable temporary symlink could be created.)r	rrrr<r=Zlgetfilecon�RuntimeErrorrr$ZENOENT�symlinkr>rrr r!r"r%�IOErrorZlsetfileconr&�remove)
r'r(Zforce�preserve_contextr)r*r@�ctx�retr-Zdsttmpr+r,rrr�symlink_atomically�s\�
�
rKcCs~tj�|�}tj�|�}tj�|�}d}d}d}	tj�|�}
|rPt��dkrPd}z�tj|tjj
|d�\}}	|
r�t�|�}|r�t�||j|j�|r�t�|t�|j��|r�t�|�\}}
|dkr�td|��t�|d�}d}|�|�|��d}t�|	|�|�r$|
�rt�||
�n
t�|�W5|�r8|��n|�rHt�|�|	�rxtj�	|	��rxzt�
|	�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.NrFrrC�w)r	r�realpathrr�existsr<r=r9�isfiler:rZmkstempr"r
�fchown�st_uid�st_gidr2r4r5Z
getfileconrD�fdopenr8r&Z
setfileconr>)rZcontentZ
preserve_moderHZpreserve_ownershipZdir_�base�fd�fZtmpnamerNrArJrIrrrr�sT�




)TT)TT)FT)TTT)�__doc__Z
__future__rr�__builtins__rr�__all__r	r<rr$r
r7rrrrrrKrrrrr�<module>s0�!
5�

?�