HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/states/__pycache__/btrfs.cpython-310.pyc
o

�N�g�(�@s�dZddlZddlZddlZddlZddlmZe�e	�Z
dZdd�Zdd�Z
d	d
�Zdd�Zd
d�Zdd�Zdd�Ze					ddd��Zeddd��Zdd�Zeddd��ZdS)z�
Manage BTRFS file systems.

:maintainer:    Alberto Planas <aplanas@suse.com>
:maturity:      new
:depends:       None
:platform:      Linux
�N)�CommandExecutionError�btrfscCsP|rdnd}t��}td||d|dd�}|ds&t�d||�t|�d	S|S)
z0
    Mount the device in a temporary place.
    �defaultszsubvol=/z
mount.mountedrF)�deviceZfstype�optsZpersist�resultzCannot mount device %s in %sN)�tempfileZmkdtemp�
__states__�log�error�_umount)r�use_defaultr�dest�res�r�E/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/btrfs.py�_mounts
�rcCstd|�td|�dS)z/
    Umount and clean the temporary place.
    zmount.unmountedzfiles.rm_rfN)r	Z	__utils__��pathrrrr&srcCs,td|�|d}td|�d}||kS)z8
    Check if the subvolume is the current default.
    �btrfs.subvolume_show�subvolume idzbtrfs.subvolume_get_default�id��__salt__)rr�name�	subvol_idZdef_idrrr�_is_default.srcCs"td|�|d}td||�S)z3
    Set the subvolume as the current default.
    rrzbtrfs.subvolume_set_defaultr)rrrrrrr�_set_default7srcCs tj�|�}dtd|�|vS)z1
    Check if the subvolume is copy on write
    �Czfile.lsattr)�osr�dirnamer)rr rrr�_is_cow?sr!cCstd|ddd�S)z2
    Disable the copy on write in a subvolume
    zfile.chattr�addr)�operatorZ
attributesrrrrr�
_unset_cowGsr$cst����fdd��}|S)zf
    Small decorator to makes sure that the mount and umount happends in
    a transactional way.
    c	
s|�d|r	|dnd�}|�dt|�dkr|dnd�}|�dd�}|didgd�}zNz#|rFt||�}|sBd	|�d
�}|d�|�||d<�|i|��}Wn!tyo}ztjd
|dd�|d�|�WYd}~nd}~wwW|rwt|�|S|r�t|�ww)Nrrr�r
Fz)Some error happends during the operation.�rr�changes�commentzDevice z cannot be mountedr(�__destz*Exception raised while mounting device: %sT)�exc_info)�get�lenr�append�	Exceptionr
rr)	�args�kwargsrrr
�retr�msg�exc��actionrr�wrapperTs8 �
����
�z__mount_device.<locals>.wrapper)�	functools�wraps)r5r6rr4r�__mount_deviceNsr9FTcCsd|digd�}tj�||�}td|�}	|	r!|d�d|�d��tdr7d|d	<|	s5d|�d
�|d|<|S|	s�tj�|�}
td|
d
d�}|d	sX|d�d|
�d��|Sztd|||d�Wntyx|d�d|���|YSwd|��|d|<|	r�|	r�|r�|r�t	|||�s�t
|||�|d|d<|s�t|�r�t|�|d|d<d
|d	<|S)af
    Makes sure that a btrfs subvolume is present.

    name
        Name of the subvolume to add

    device
        Device where to create the subvolume

    qgroupids
         Add the newly created subcolume to a qgroup. This parameter
         is a list

    set_default
        If True, this new subvolume will be set as default when
        mounted, unless subvol option in mount is used

    copy_on_write
        If false, set the subvolume with chattr +C

    force_set_default
        If false and the subvolume is already present, it will not
        force it as default if ``set_default`` is True

    Fr&�btrfs.subvolume_existsr(�
Subvolume z already present�testNrz will be createdr'zfile.directoryT)�makedirszError creating z
 directoryzbtrfs.subvolume_create)r�	qgroupidszError creating subvolume zCreated subvolume �_defaultZ_no_cow)
rr�joinrr-�__opts__r r	rrrr!r$)rrr>Zset_defaultZ
copy_on_writeZforce_set_defaultr)r1r�exists�_pathrrrr�subvolume_createdssT$������
�rDcCs�|digd�}tj�||�}td|�}|s!|d�d|�d��tdr7d|d	<|r5d|�d
�|d|<|S|r;dnd}|shz
td
||d�Wnty^|d�d|���|YSwd|��|d|<d|d	<|S)z�
    Makes sure that a btrfs subvolume is removed.

    name
        Name of the subvolume to remove

    device
        Device where to remove the subvolume

    commit
        Wait until the transaction is over

    Fr&r:r(r;z already missingr<Nrz will be removedr'Zafterzbtrfs.subvolume_delete)�commitzError removing subvolume zRemoved subvolume T)rrr@rr-rAr)rrrEr)r1rrBrrr�subvolume_deleted�s2��rFcCsZi}|��D]$\}}||d}|dur|dkrd}n	||kr"d}nd}|r*|||<q|S)a#Calculate the difference between the current and the expected
    properties

    * 'expected' is expressed in a dictionary like: {'property': value}

    * 'current' contains the same format retuned by 'btrfs.properties'

    If the property is not available, will throw an exception.

    �valueFzN/AT)�items)�expected�current�
differenceZ	_propertyrGZ
current_valueZneeds_updaterrr�_diff_properties�s�rLc

Ks|digd�}|r&tj�|�rtj�|tj�|tjj��}n
tj�||�}n|}tj�|�s;|d�d|�d��|Sdd�|��D�}i}zt	d|�}Wn(t
yv}z|d�d	|���|d�d
|���|WYd}~Sd}~wwzt||�}	Wnty�|d�d|���|YSwt
d
r�d|d<|	r�|	|d<|Sd|��}
|d�|
�|S|	r�d�dd�|	��D��}t	d||d�t	d|�}t||�}|r�d�||�}
|d�|
�|S|d�d|���|	|d<n
|d�d|���d|d<|S)a5
    Makes sure that a list of properties are set in a subvolume, file
    or device.

    name
        Name of the object to change

    device
        Device where the object lives, if None, the device will be in
        name

    use_default
        If True, this subvolume will be resolved to the default
        subvolume assigned during the create operation

    properties
        Dictionary of properties

    Valid properties are 'ro', 'label' or 'compression'. Check the
    documentation to see where those properties are valid for each
    object.

    Fr&r(zObject z
 not foundcSs.i|]\}}|t|�tur|nt|����qSr)�type�bool�str�lower��.0�k�vrrr�
<dictcomp>Gs"�zproperties.<locals>.<dictcomp>zbtrfs.propertieszError reading properties from zCurrent error NzSome property not found in r<rr'z!No properties will be changed in �,css"�|]\}}|�d|��VqdS)�=NrrQrrr�	<genexpr>cs� zproperties.<locals>.<genexpr>)�setz(Properties {} failed to be changed in {}zProperties changed in zProperties not changed in T)rr�isabsr@�relpath�seprBr-rHrrrL�KeyErrorrA�format)
rrr
r)�
propertiesr1rZcurrent_properties�eZproperties_to_setr2Z_propertiesZproperties_failedrrrr_sn�
����
�
�
r_)NFTTN)FN)�__doc__r7�loggingZos.pathrrZsalt.exceptionsr�	getLogger�__name__r
Z__virtualname__rrrrr!r$r9rDrFrLr_rrrr�<module>s6	
	%�X1