o
    +ked                     @   s  d Z ddlZddlZddlZddlZddlZddlZddlmZ	 ddl
mZ ddlmZ e ZddlmZmZmZmZ dZejd	r}ejd
dZedeZeD ]*Zedr|eddZejddgedZe	ed d Zee	dkrzdZ nqRdddZ dddZ!dddZ"dS )zPA basic extended attributes (xattr) implementation for Linux, FreeBSD and macOS.    N)parse   )prepare_subprocess_env)create_logger)	listxattrgetxattrsetxattrENOATTRFlinux
LD_PRELOAD z[ :]ZlibfakerootT)systemZfakerootz-v)envasciiz1.20.2c              	   C   s   t j| ddT}| }d\}}zt||| W n ty(   Y W d   dS w zt|}W n ty?   Y W d   dS w ||vrM	 W d   dS t|||kW  d   S 1 s^w   Y  dS )z4Determine if xattr is enabled on the filesystem
    zborg-tmp)dirprefix)s	   user.names   valueNF)tempfileNamedTemporaryFilefilenor   OSErrorr   r   )pathffdnamevaluenames r   .usr/lib/python3.10/site-packages/borg/xattr.py
is_enabled)   s(   	$r   c                 C   s   t | tr
t| } i }zAt| |d}|D ]5}zt| ||dp d||< W q tyJ } z|jtfv r3nt	
d|jddt| W Y d}~qd}~ww W |S  tyk } z|jtjtjfv r_n W Y d}~|S d}~ww )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 (bytes) to values (bytes or None).
    None indicates, as a xattr value, an empty value, i.e. a value of length zero.
    follow_symlinksNz&when getting extended attribute %s: %sreplaceerrors)
isinstancestrosfsencoder   r   r   errnor	   loggerwarningdecodeENOTSUPEPERM)r   r!   resultr   r   er   r   r   get_all<   s0   


r1   c                 C   s   t | tr
t| } d}| D ]Q\}}zt| ||pd|d W q tya } z5d}|jtjkr7dt| }n|jtj	krHdt
|t|f }nt|}td|jdd	| W Y d
}~qd
}~ww |S )a  
    Set all extended attributes on *path* from 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.
    *xattrs* is mapping maps xattr names (bytes) to values (bytes or None).
    None indicates, as a xattr value, an empty value, i.e. a value of length zero.

    Return warning status (True means a non-fatal exception has happened and was dealt with).
    F    r    Tz too big for this filesystem (%s)z/fs full or xattr too big? [xattr len = %d] (%s)z&when setting extended attribute %s: %sr"   r#   N)r%   r&   r'   r(   itemsr   r   r)   ZE2BIGENOSPClenr*   r+   r,   )r   Zxattrsr!   r+   kvr0   Zerr_strr   r   r   set_alle   s"   

"r8   )N)F)#__doc__r)   r'   re
subprocesssysr   packaging.versionr   parse_versionhelpersr   r*   r   platformr   r   r   r	   ZXATTR_FAKEROOT
startswithenvirongetr   splitZpreloadsZpreloadr   check_outputZfakeroot_outputr,   Zfakeroot_versionr   r1   r8   r   r   r   r   <module>   s8    



)