File: //opt/cloudlinux/venv/lib64/python3.11/site-packages/clwizard/__pycache__/utils.cpython-311.pyc
�
����� � � d dl Z d dlZd dlZd dlmZ d dlmZ d dlZddlm Z ddl
mZ edd�� � Zd � Z
d
� Zd� Zd� Zd
� ZdS )� N)�contextmanager)�Iterable� )�CRASH_LOG_PATH)�PackageMissingErrorTc # �� K � | dz } t |dd�� � 5 }|V � |r:|� � � t j |� � � � � ddd� � n# 1 swxY w Y t j || � � t j |� � dS # t t f$ r Y dS w xY w# t j |� � w # t t f$ r Y w w xY wxY w)z� Writeable file object that atomically updates a file (using a temporary file).
:param filepath: the file path to be opened
:param fsync: whether to force write the file to disk
z.tmp�w�utf-8��encodingN) �open�flush�os�fsync�fileno�rename�remove�IOError�OSError)�filepathr �tmppath�fs �py/clwizard/utils.py�atomic_writer sK � � � � ���G��
�'�3��
1�
1�
1� %�Q��G�G�G��
%���� � � ��������$�$�$� %� %� %� %� %� %� %� %� %� %� %���� %� %� %� %�
� �'�8�$�$�$� ��I�g���������!� � � ��D�D� ����� ��I�g��������!� � � ��D� ������se �B7 �AA(�B7 �(A,�,B7 �/A,�0B7 � B �B4�3B4�7C%�9C�
C%�C"�C%�!C"�"C%c � � d� }| �dS t t j | � � � � � � � }n# t j $ r Y dS w xY w ||� � S )a�
Detects if the recorded background-install worker is still running.
Only the worker PID recorded in the (root-only, flock-protected) wizard
config is consulted, and only when that PID is BOTH alive AND still presents
a genuine wizard-worker cmdline. This prevents an unrelated local process
with a forged argv from being mistaken for the worker, and treats a dead or
PID-reused entry as "not running".
c �V � h d�t | � � k ph d�t | � � k S )N> �/usr/sbin/cloudlinux-wizard�install�
--no-async> �/sbin/cloudlinux-wizardr r )�set)�cmdlines r �_is_wizard_cmdlinez9is_background_process_running.<locals>._is_wizard_cmdline6 s8 � �
E�D�D��G���T�
T�C�C�C�s�7�|�|�S�
� NF)�list�psutil�Processr"