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/beacons/__pycache__/inotify.cpython-310.pyc
o

�N�g�/�@s�dZddlZddlZddlZddlZddlZddlZz.ddlZdZ	ej
ejBejBZ
iZee�D]Ze�d�rFedd���Zeee�ee<q0Wn
eyUdZ	dZ
YnwdZe�e�Zdd	�Zd
d�Zdd
�Zdd�Zdd�Zdd�Zdd�Z dS)a
Watch files and translate the changes into salt events

:depends:   - pyinotify Python module >= 0.9.5

:Caution:   Using generic mask options like open, access, ignored, and
            closed_nowrite with reactors can easily cause the reactor
            to loop on itself. To mitigate this behavior, consider
            setting the `disable_during_state_run` flag to `True` in
            the beacon configuration.

:note: The `inotify` beacon only works on OSes that have `inotify`
       kernel support.

�NTZIN_�F�inotifycCs trtSd}t�d|�d|fS)Nzpyinotify library is missing.z!Unable to load inotify beacon: %sF)�
HAS_PYINOTIFY�__virtualname__�log�error)�err_msg�r	�H/opt/saltstack/salt/lib/python3.10/site-packages/salt/beacons/inotify.py�__virtual__,s
rcCst�|d�S)z1
    Return the int that represents the mask
    r)�MASKS�get)�maskr	r	r
�	_get_mask4srcCstd�|�dS)z
    Enqueue the event
    �
inotify.queueN)�__context__�append)Zreventr	r	r
�_enqueue;srcCst|�dd�}|�d�}|tvr6t��td<t��}t�|t�t|<d|vr6t|dt	�r6|dr6t|�
�t|S)zL
    Check the context for the notifier and construct it if not present
    �_beacon_namer�	.notifierrZcoalesce)r
r�collections�deque�	pyinotifyZWatchManagerZNotifierr�
isinstance�boolZcoalesce_events)�config�beacon_name�notifier�wmr	r	r
�
_get_notifierBs
��rcCsFgd�}t|t�sdStjj�|�}d|vrdSt|dt�s!dS|�d�D]z}t|d|t�s4dStdd�|d|D��sDd	Sd
|d|vrZt|d|d
t	�sZdSd|d|vrpt|d|dt	�spd
Sd|d|vr�t|d|dt�s�dS|d|dD]}||vr�dd�
|�fSq�q&dS)z+
    Validate the beacon configuration
    )�accessZattribZ
close_nowriteZclose_write�create�deleteZdelete_selfZexcl_unlinkZignored�modifyZ
moved_fromZmoved_toZ	move_selfZoneshotZonlydir�openZunmount)Fz0Configuration for inotify beacon must be a list.�files)Fz4Configuration for inotify beacon must include files.)Fz?Configuration for inotify beacon invalid, files must be a dict.)Fz@Configuration for inotify beacon must be a list of dictionaries.css�|]}|dvVqdS))r�recurse�auto_addNr	)�.0�jr	r	r
�	<genexpr>�s
��
�zvalidate.<locals>.<genexpr>)FzNConfiguration for inotify beacon must contain mask, recurse or auto_add items.r')Fz:Configuration for inotify beacon auto_add must be boolean.r&)Fz9Configuration for inotify beacon recurse must be boolean.r)Fz3Configuration for inotify beacon mask must be list.Fz8Configuration for inotify beacon invalid mask option {}.)TzValid beacon configuration)r�list�salt�utils�beacons�list_to_dict�dictr
�anyr�format)rZ
VALID_MASK�pathrr	r	r
�validateUsB

����r4c	Cspdg}tjj�||�}tjj�|�}g}t|�}|j}|�d�r�|��|�	�t
d}|r�|��}d}|j}|dkrN||�
di�vrDn
tj�|�}|dks;|d�
|i��
dd�}	|	r�t|	t�r�|	D]I}
t|
t�r�tt|
��}|
|�
d	d
�r�zt�||j�r�d
}Wqcty�t�d|�Yqcw|}
qcd|
vr�t�|j|
�r�d
}qc|j�|
�r�d
}qc|r�|j|j|jd
�}|�|�nt�d|j|�|s.t �}
|j!D]}|
�"|j!|j�q�|�
dd�D]�}t|d|t��r/|d|�
dt#�}t|t��rd}|D]	}|t$|�O}�qn
t|t%��rt$|�}n|}|}|d|�
dd
�}|d|�
dd
�}nt#}d
}d
}||
v�ro|j!D]0}||j!|jk�rld
}|j!|j&|k�rUd}|j!|j'|k�r`d}|�rl|j(||||d��q=q�tj�)|��r�|d|�
dd�}	d}t|	t��r�g}|	D]}
t|
t��r�|�t|
�d��q�|�|
��q�t*�+|�}|j,|||||d�q�|S)a�	
    Watch the configured files

    Example Config

    .. code-block:: yaml

        beacons:
          inotify:
            - files:
                /path/to/file/or/dir:
                  mask:
                    - open
                    - create
                    - close_write
                  recurse: True
                  auto_add: True
                  exclude:
                    - /path/to/file/or/dir/exclude1
                    - /path/to/file/or/dir/exclude2
                    - /path/to/file/or/dir/regex[a-m]*$:
                        regex: True
            - coalesce: True

    The mask list can contain the following events (the default mask is create,
    delete, and modify):

    * access            - File accessed
    * attrib            - File metadata changed
    * close_nowrite     - Unwritable file closed
    * close_write       - Writable file closed
    * create            - File created in watched directory
    * delete            - File deleted from watched directory
    * delete_self       - Watched file or directory deleted
    * modify            - File modified
    * moved_from        - File moved out of watched directory
    * moved_to          - File moved into watched directory
    * move_self         - Watched file moved
    * open              - File opened

    The mask can also contain the following options:

    * dont_follow       - Don't dereference symbolic links
    * excl_unlink       - Omit events for children after they have been unlinked
    * oneshot           - Remove watch after one event
    * onlydir           - Operate only if name is directory

    recurse:
      Recursively watch files in the directory
    auto_add:
      Automatically start watching files that are created in the watched directory
    exclude:
      Exclude directories or files from triggering events in the watched directory.
      Can use regex if regex is set to True
    coalesce:
      If this coalescing option is enabled, events are filtered based on
      their unicity, only unique events are enqueued, doublons are discarded.
      An event is unique when the combination of its fields (wd, mask,
      cookie, name) is unique among events of a same batch. After a batch of
      events is processed any events are accepted again.
      This option is top-level (at the same level as the path) and therefore
      affects all paths that are being watched. This is due to this option
      being at the Notifier level in pyinotify.
    r�rT�/r%�exclude�ZregexFzFailed to compile regex: %s�*)�tagr3ZchangezExcluding %s from event for %sr	rrr&r')r�recr'N)r;r'Zexclude_filter)-r,r-r.Zremove_hidden_optionsr/rZ_watch_managerZcheck_eventsZread_eventsZprocess_eventsr�popleftr3r
�os�dirnamerr+r0�next�iter�re�search�pathname�	Exceptionr�warning�fnmatch�
startswithZmasknamer�info�setZwatches�add�DEFAULT_MASKr�bytesrr'Zupdate_watch�existsrZ
ExcludeFilterZ	add_watch)rZ	whitelist�retrr�queue�event�_appendr3Zexcludesr7Z_exclude�sub�current�wdrZr_maskr;r'�updateZexclr	r	r
�beacon�s�B
�
������+
�


��	
�rVcCsFtjj�|�}|�dd�}|�d�}|tvr!t|��t|=dSdS)Nrrr)r,r-r.r/r
r�stop)rrrr	r	r
�closeas

�rX)!�__doc__rrF�loggingr=rAZsalt.utils.beaconsr,rrZ	IN_CREATEZ	IN_DELETEZ	IN_MODIFYrKr�dir�varrG�lower�key�getattr�ImportErrorr�	getLogger�__name__rrrrrr4rVrXr	r	r	r
�<module>s@
���
[2