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ic extended attributes (xattr) implementation for Linux, FreeBSD and MacOS X.    N)CDLLcreate_string_buffer	c_ssize_tc_size_tc_char_pc_intc_uint32	get_errno)find_library)parse   )Bufferprepare_subprocess_env      )limitc             C   sV   t j| dd>}yt|j dd W n tk
r8   dS X t|j ddkS Q R X dS )z4Determine if xattr is enabled on the filesystem
    zborg-tmp)dirprefixz	user.names   valueFN)tempfileZNamedTemporaryFilesetxattrfilenoOSErrorgetxattr)pathfd r   /usr/lib64/python3.6/xattr.py
is_enabled   s    r   Tc             C   s   yhi }t | |d}xR|D ]J}yt| ||d||< W q tk
r` } z|jtkrP W Y dd}~X qX qW |S  tk
r } z|jtjtjfkri S W Y dd}~X nX dS )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)	listxattrr   r   errnoENOATTRZENOTSUPZEPERM)r   r   resultnamesnameer   r   r   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_LIBCclinuxz	libc.so.6darwinz
libc.dylib)fileF
LD_PRELOAD z[ :]Zlibfakeroot)systemZfakerootz-v)envasciiz1.20.2)Z	use_errnoc             C   s   | j ddd S )zMsplit a list of zero-terminated strings into python not-zero-terminated bytes    Nr   )split)bufr   r   r   split_string0m   s    r4   c             C   sL   g }t | }x:|rF|d }|jt|dd|   |d| d }qW |S )zMsplit a list of length-prefixed strings into python not-length-prefixed bytesr   r   N)
memoryviewappendbytes)r3   r"   ZmvZlengthr   r   r   split_lstringr   s    r8   c               @   s   e Zd ZdZdS )BufferTooSmallErrorzBthe buffer given to a xattr function was too small for the result.N)__name__
__module____qualname____doc__r   r   r   r   r9   }   s   r9   c             C   s   | dk rht  }|r"|tjkr"tnFytj|}W n tk
rH   d}Y nX t|tr\d| }t	||||r|| t
tkr|t| S )Nr   r,   z<FD %d>)r	   r    ZERANGEr9   osstrerror
ValueError
isinstanceintr   lenbuffer)rvr   detect_buffer_too_smallr%   msgr   r   r   _check   s    

rH   c             C   sr   t |trtj|}tt}xPtj|}yt| ||||dd}W n tk
r^   |d9 }Y qX ||j	fS qW d S )NT)rF   r   )
rA   strr>   fsencoderC   rD   getrH   r9   raw)funcr   sizer3   nr   r   r   _listxattr_inner   s    


rP   c             C   s~   t |trtj|}tj|}tt}xRtj|}yt| |||||dd}W n tk
rj   |d9 }Y q(X ||j	fS q(W d S )NT)rF   r   )
rA   rI   r>   rJ   rC   rD   rK   rH   r9   rL   )rM   r   r$   rN   r3   rO   r   r   r   _getxattr_inner   s    



rQ   c             C   sX   t |trtj|}tj|}|o*tj|}|r8t|nd}t| |||||dd d S )Nr   F)rF   )rA   rI   r>   rJ   rC   rH   )rM   r   r$   valuerN   r   r   r   _setxattr_inner   s    


rS   )r   c               s4    fdd}t || \}}dd t|d | D S )Nc                s<   t | trtj| ||S  r*tj| ||S tj| ||S d S )N)rA   rB   libc
flistxattrr   
llistxattr)r   r3   rN   )r   r   r   rM      s
    
zlistxattr.<locals>.funcc             S   s&   g | ]}|r|j d  rtj|qS )s   system.posix_acl_)
startswithr>   fsdecode).0r$   r   r   r   
<listcomp>   s    zlistxattr.<locals>.<listcomp>)rP   r4   )r   r   rM   rO   r3   r   )r   r   r      s    	r   c               s,    fdd}t || |\}}|d | p*d S )Nc                sB   t | trtj| |||S  r.tj| |||S tj| |||S d S )N)rA   rB   rT   	fgetxattrr   	lgetxattr)r   r$   r3   rN   )r   r   r   rM      s
    
zgetxattr.<locals>.func)rQ   )r   r$   r   rM   rO   r3   r   )r   r   r      s    	r   c               s    fdd}t || || d S )Nc                sL   d}t | tr tj| ||||S  r6tj| ||||S tj| ||||S d S )Nr   )rA   rB   rT   	fsetxattrr   	lsetxattr)r   r$   rR   rN   flags)r   r   r   rM      s    
zsetxattr.<locals>.func)rS   )r   r$   rR   r   rM   r   )r   r   r      s    
r   c               s4    fdd}t || \}}dd t|d | D S )Nc                sB   t | trtj| ||tS  r.tj| ||tS tj| ||tS d S )N)rA   rB   rT   rU   XATTR_NOFLAGSr   XATTR_NOFOLLOW)r   r3   rN   )r   r   r   rM     s
    
zlistxattr.<locals>.funcc             S   s   g | ]}|rt j|qS r   )r>   rX   )rY   r$   r   r   r   rZ     s    zlistxattr.<locals>.<listcomp>)rP   r4   )r   r   rM   rO   r3   r   )r   r   r     s    	c               s,    fdd}t || |\}}|d | p*d S )Nc                sN   t | trtj| |||dtS  r6tj| |||dtS tj| |||dtS d S )Nr   )rA   rB   rT   r[   r`   r   ra   )r   r$   r3   rN   )r   r   r   rM     s
    
zgetxattr.<locals>.func)rQ   )r   r$   r   rM   rO   r3   r   )r   r   r     s    	c               s    fdd}t || || d S )Nc                sN   t | trtj| |||dtS  r6tj| |||dtS tj| |||dtS d S )Nr   )rA   rB   rT   r]   r`   r   ra   )r   r$   rR   rN   )r   r   r   rM   '  s
    
zsetxattr.<locals>.func)rS   )r   r$   rR   r   rM   r   )r   r   r   &  s    	Zfreebsduser.   user.c               s4    fdd}t || \}}dd t|d | D S )Nc                sB   t | trtj| t||S  r.tj| t||S tj| t||S d S )N)rA   rB   rT   extattr_list_fdnsextattr_list_fileextattr_list_link)r   r3   rN   )r   r   r   rM   I  s
    
zlistxattr.<locals>.funcc             S   s   g | ]}|rt tj| qS r   )r   r>   rX   )rY   r$   r   r   r   rZ   S  s    zlistxattr.<locals>.<listcomp>)rP   r8   )r   r   rM   rO   r3   r   )r   r   r   H  s    	c               sX    fdd}t |trtnt}|j|r8|t|d  }t|| |\}}|d | pVd S )Nc                sH   t | trtj| t|||S  r2tj| t|||S tj| t|||S d S )N)rA   rB   rT   extattr_get_fdre   extattr_get_fileextattr_get_link)r   r$   r3   rN   )r   r   r   rM   V  s
    
zgetxattr.<locals>.func)rA   rI   r   prefix_brW   rC   rQ   )r   r$   r   rM   _prefixrO   r3   r   )r   r   r   U  s    
c               sJ    fdd}t |trtnt}|j|r8|t|d  }t|| || d S )Nc                sH   t | trtj| t|||S  r2tj| t|||S tj| t|||S d S )N)rA   rB   rT   extattr_set_fdre   extattr_set_fileextattr_set_link)r   r$   rR   rN   )r   r   r   rM   h  s
    
zsetxattr.<locals>.func)rA   rI   r   rk   rW   rC   rS   )r   r$   rR   r   rM   rl   r   )r   r   r   g  s
    
c            C   s   g S )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   )r   r   r   r   r   r   y  s    c            C   s   dS )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   )r   r$   r   r   r   r   r     s    c            C   s   dS )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   )r   r$   rR   r   r   r   r   r     s    i   )N)Tr1   )NF)rb   rc   )Wr=   r    r>   re
subprocesssysr   Zctypesr   r   r   r   r   r   r   r	   Zctypes.utilr
   Zpackaging.versionr   Zparse_versionZhelpersr   r   r!   AttributeErrorZENODATArD   r   r&   ZHINT_MSGZLIBC_NOT_FOUND_NO_FALLBACK_MSGZLIBC_NOT_FOUND_FNAME_MSGenvironrK   Z	libc_nameplatformrW   printstderr	ExceptionZXATTR_FAKEROOTr+   r2   ZpreloadsZpreloadr.   Zcheck_outputZfakeroot_outputdecodeZfakeroot_versionrT   r   r%   r4   r8   r9   rH   rP   rQ   rS   r   ZargtypesZrestyperV   rU   r   r^   r]   r   r\   r[   r`   ra   rd   rg   rf   rh   rj   ri   rm   ro   rn   re   ZEXTATTR_NAMESPACE_USERr   rk   r   r   r   r   <module>   s   (






	

