Current File : //usr/lib64/python3.6/site-packages/borg/__pycache__/xattr.cpython-36.pyc
3

y��b�@�@s�dZddlZddlZddlZddlZddlZddlZddlmZm	Z	m
Z
mZmZm
Z
mZmZddlmZddlmZddlmZmZy
ejZWnek
r�ejZYnXee	dGd
�ZdHdd�ZdIdd�ZdZdeZdeZ ej!j"d�p�ed�Z#e#dk�r8ej$j%d��rdZ#n(ej$dk�r"dZ#ne&eej'd�e(e��dZ)ej$j%d��r�ej!j"dd�Z*ej+de*�Z,xde,D]\Z-e-j%d��rjed
d�Z.ej/d d!ge.d"�Z0ee0j1d#�j+�dJ�Z2e2ed$�k�r�e-Z#d
Z)P�qjWyee#d
d%�Z3Wn0e4k
�r
Z5ze(e e5��WYddZ5[5XnXd&d'�Z6d(d)�Z7Gd*d+�d+e(�Z8dKd,d-�Z9d.d/�Z:d0d1�Z;d2d3�Z<ej$j%d��rbeeefe3j=_>e
e3j=_?eeefe3j@_>e
e3j@_?e
eefe3jA_>e
e3jA_?eeeee
fe3jB_>e
e3jB_?eeeee
fe3jC_>e
e3jC_?e
eeee
fe3jD_>e
e3jD_?eeeefe3jE_>e
e3jE_?eeeefe3jF_>e
e3jF_?e
eeefe3jG_>e
e3jG_?d
d4�d5d6�Z=d
d4�d7d8�ZEd
d4�d9d:�ZB�n:ej$dk�rDeeee
fe3j=_>e
e3j=_?e
eee
fe3jA_>e
e3jA_?eeeeee
fe3jB_>e
e3jB_?e
eeeee
fe3jD_>e
e3jD_?eeeeee
fe3jE_>e
e3jE_?e
eeeee
fe3jG_>e
e3jG_?dZHdZId
d4�d;d6�Z=d
d4�d<d8�ZEd
d4�d=d:�ZB�nXej$j%d>��rre
e
eefe3jJ_>e
e3jJ_?ee
eefe3jK_>e
e3jK_?ee
eefe3jL_>e
e3jL_?e
e
eeefe3jM_>e
e3jM_?ee
eeefe3jN_>e
e3jN_?ee
eeefe3jO_>e
e3jO_?e
e
eeefe3jP_>e
e3jP_?ee
eeefe3jQ_>e
e3jQ_?ee
eeefe3jR_>e
e3jR_?dZSZTdL\ZUZVd
d4�dAd6�Z=d
d4�dBd8�ZEd
d4�dCd:�ZBn*d
d4�dDd6�Z=d
d4�dEd8�ZEd
d4�dFd:�ZBdS)MzRA basic extended attributes (xattr) implementation for Linux, FreeBSD and MacOS X.�N)�CDLL�create_string_buffer�	c_ssize_t�c_size_t�c_char_p�c_int�c_uint32�	get_errno)�find_library)�parse�)�Buffer�prepare_subprocess_env��)�limitcCsVtj|dd��>}yt|j�dd�Wntk
r8dSXt|j�d�dkSQRXdS)z4Determine if xattr is enabled on the filesystem
    zborg-tmp)�dir�prefixz	user.namesvalueFN)�tempfileZNamedTemporaryFile�setxattr�fileno�OSError�getxattr)�path�fd�r�/usr/lib64/python3.6/xattr.py�
is_enabledsrTcCs�yhi}t||d�}xR|D]J}yt|||d�||<Wqtk
r`}z|jtkrP�WYdd}~XqXqW|Stk
r�}z|jtjtjfkr�iSWYdd}~XnXdS)a�
    Return all extended attributes on *path* as a mapping.

    *path* can either be a path (str or bytes) or an open file descriptor (int).
    *follow_symlinks* indicates whether symlinks should be followed
    and only applies when *path* is not an open file descriptor.

    The returned mapping maps xattr names (str) to values (bytes or None).
    None indicates, as a xattr value, an empty value, i.e. a value of length zero.
    )�follow_symlinksN)�	listxattrrr�errno�ENOATTRZENOTSUPZEPERM)rr�result�names�name�errr�get_all%s

r&z<Try installing ldconfig, gcc/cc or objdump or use BORG_LIBC.z)Can't find C library. No fallback known. zCan't find C library [%s]. Z	BORG_LIBC�c�linuxz	libc.so.6�darwinz
libc.dylib)�fileF�
LD_PRELOAD�z[ :]Zlibfakeroot)�systemZfakerootz-v)�env�asciiz1.20.2)Z	use_errnocCs|jd�dd�S)zMsplit a list of zero-terminated strings into python not-zero-terminated bytes�Nr���)�split)�bufrrr�
split_string0msr4cCsLg}t|�}x:|rF|d}|jt|dd|���|d|d�}qW|S)zMsplit a list of length-prefixed strings into python not-length-prefixed bytesrrN)�
memoryview�append�bytes)r3r"ZmvZlengthrrr�
split_lstringrsr8c@seZdZdZdS)�BufferTooSmallErrorzBthe buffer given to a xattr function was too small for the result.N)�__name__�
__module__�__qualname__�__doc__rrrrr9}sr9cCs�|dkrht�}|r"|tjkr"t�nFytj|�}Wntk
rHd}YnXt|t�r\d|}t	|||��|r||t
t�kr|t�|S)Nrr,z<FD %d>)r	r ZERANGEr9�os�strerror�
ValueError�
isinstance�intr�len�buffer)�rvr�detect_buffer_too_smallr%�msgrrr�_check�s

rHcCsrt|t�rtj|�}tt�}xPtj|�}yt||||�|dd�}Wntk
r^|d9}YqX||j	fSqWdS)NT)rFr)
rA�strr>�fsencoderCrD�getrHr9�raw)�funcr�sizer3�nrrr�_listxattr_inner�s


rPcCs~t|t�rtj|�}tj|�}tt�}xRtj|�}yt|||||�|dd�}Wntk
rj|d9}Yq(X||j	fSq(WdS)NT)rFr)
rArIr>rJrCrDrKrHr9rL)rMrr$rNr3rOrrr�_getxattr_inner�s



rQcCsXt|t�rtj|�}tj|�}|o*tj|�}|r8t|�nd}t|||||�|dd�dS)NrF)rF)rArIr>rJrCrH)rMrr$�valuerNrrr�_setxattr_inner�s


rS)rcs4�fdd�}t||�\}}dd�t|d|��D�S)Ncs<t|t�rtj|||�S�r*tj|||�Stj|||�SdS)N)rArB�libc�
flistxattrr�
llistxattr)rr3rN)rrrrM�s

zlistxattr.<locals>.funccSs&g|]}|r|jd�rtj|��qS)ssystem.posix_acl_)�
startswithr>�fsdecode)�.0r$rrr�
<listcomp>�szlistxattr.<locals>.<listcomp>)rPr4)rrrMrOr3r)rrr�s	rcs,�fdd�}t|||�\}}|d|�p*dS)NcsBt|t�rtj||||�S�r.tj||||�Stj||||�SdS)N)rArBrT�	fgetxattrr�	lgetxattr)rr$r3rN)rrrrM�s

zgetxattr.<locals>.func)rQ)rr$rrMrOr3r)rrr�s	rcs�fdd�}t||||�dS)NcsLd}t|t�r tj|||||�S�r6tj|||||�Stj|||||�SdS)Nr)rArBrT�	fsetxattrr�	lsetxattr)rr$rRrN�flags)rrrrM�s
zsetxattr.<locals>.func)rS)rr$rRrrMr)rrr�s
rcs4�fdd�}t||�\}}dd�t|d|��D�S)NcsBt|t�rtj|||t�S�r.tj|||t�Stj|||t�SdS)N)rArBrTrU�
XATTR_NOFLAGSr�XATTR_NOFOLLOW)rr3rN)rrrrM
s

zlistxattr.<locals>.funccSsg|]}|rtj|��qSr)r>rX)rYr$rrrrZszlistxattr.<locals>.<listcomp>)rPr4)rrrMrOr3r)rrrs	cs,�fdd�}t|||�\}}|d|�p*dS)NcsNt|t�rtj||||dt�S�r6tj||||dt�Stj||||dt�SdS)Nr)rArBrTr[r`rra)rr$r3rN)rrrrMs

zgetxattr.<locals>.func)rQ)rr$rrMrOr3r)rrrs	cs�fdd�}t||||�dS)NcsNt|t�rtj||||dt�S�r6tj||||dt�Stj||||dt�SdS)Nr)rArBrTr]r`rra)rr$rRrN)rrrrM's

zsetxattr.<locals>.func)rS)rr$rRrrMr)rrr&s	Zfreebsd�user.�user.cs4�fdd�}t||�\}}dd�t|d|��D�S)NcsBt|t�rtj|t||�S�r.tj|t||�Stj|t||�SdS)N)rArBrT�extattr_list_fd�ns�extattr_list_file�extattr_list_link)rr3rN)rrrrMIs

zlistxattr.<locals>.funccSsg|]}|rttj|��qSr)rr>rX)rYr$rrrrZSszlistxattr.<locals>.<listcomp>)rPr8)rrrMrOr3r)rrrHs	csX�fdd�}t|t�rtnt}|j|�r8|t|�d�}t|||�\}}|d|�pVdS)NcsHt|t�rtj|t|||�S�r2tj|t|||�Stj|t|||�SdS)N)rArBrT�extattr_get_fdre�extattr_get_file�extattr_get_link)rr$r3rN)rrrrMVs

zgetxattr.<locals>.func)rArIr�prefix_brWrCrQ)rr$rrM�_prefixrOr3r)rrrUs
csJ�fdd�}t|t�rtnt}|j|�r8|t|�d�}t||||�dS)NcsHt|t�rtj|t|||�S�r2tj|t|||�Stj|t|||�SdS)N)rArBrT�extattr_set_fdre�extattr_set_file�extattr_set_link)rr$rRrN)rrrrMhs

zsetxattr.<locals>.func)rArIrrkrWrCrS)rr$rRrrMrlr)rrrgs

cCsgS)a
        Return list of xattr names on a file.

        *path* can either be a path (str or bytes) or an open file descriptor (int).
        *follow_symlinks* indicates whether symlinks should be followed
        and only applies when *path* is not an open file descriptor.
        r)rrrrrryscCsdS)al
        Read xattr and return its value (as bytes) or None if its empty.

        *path* can either be a path (str or bytes) or an open file descriptor (int).
        *name* is the name of the xattr to read (str).
        *follow_symlinks* indicates whether symlinks should be followed
        and only applies when *path* is not an open file descriptor.
        Nr)rr$rrrrr�scCsdS)a�
        Write xattr on *path*.

        *path* can either be a path (str or bytes) or an open file descriptor (int).
        *name* is the name of the xattr to read (str).
        *value* is the value to write. It is either bytes or None. The latter
        signals that the value shall be empty (size equals zero).
        *follow_symlinks* indicates whether symlinks should be followed
        and only applies when *path* is not an open file descriptor.
        Nr)rr$rRrrrrr�si)N)Tr1)NF)rbrc)Wr=r r>�re�
subprocess�sysrZctypesrrrrrrrr	Zctypes.utilr
Zpackaging.versionrZ
parse_versionZhelpersr
rr!�AttributeErrorZENODATArDrr&ZHINT_MSGZLIBC_NOT_FOUND_NO_FALLBACK_MSGZLIBC_NOT_FOUND_FNAME_MSG�environrKZ	libc_name�platformrW�print�stderr�	ExceptionZXATTR_FAKEROOTr+r2ZpreloadsZpreloadr.Zcheck_outputZfakeroot_output�decodeZfakeroot_versionrTrr%r4r8r9rHrPrQrSrZargtypesZrestyperVrUrr^r]rr\r[r`rardrgrfrhrjrirmrornreZEXTATTR_NAMESPACE_USERrrkrrrr�<module>s�(