,ruA% d Z ddlZddlZddlZddlmZ ddlmZmZm Z ddl mZmZ ddl mZ ddlmZmZ ddlZej Zej ej z ej z Zd Zed!d Zed efd Zd"deeef d ee fdZd ed efdZed ed edede fd Z!dededeeef dee fdZ" ed defd Z#dede fdZ$ddddedefd Z%dS )#zF Mostly copy-pasting from `safe_fileops.py` of the Imunify360 project N)ProcessPoolExecutor) ExitStackcontextmanagersuppress) lru_cachepartial)Path)OptionalUnionc t j dk rt j g t j | t j | || S )Nr )osgetuid setgroupssetgidsetuid)uidgidfunargss R/opt/imunify360/venv/lib/python3.11/site-packages/restore_infected/safe_fileops.pydropr sI y{{a RIcNNNIcNNN3: c # N K t j | || } |V t t 5 t j | ddd dS # 1 swxY w Y dS # t t 5 t j | ddd w # 1 swxY w Y w xY w)zR Context manager which wraps os.open and close file descriptor at the end dir_fdN)r openr OSErrorclose)pathflagsr fds r open_fdr" s# uV , , ,B g HRLLL Xg HRLLL s@ A" AAA"B$7BB$BB$B B$namec # K t | t j 5 }t j d | }| |k rt d |V ddd dS # 1 swxY w Y dS )z Context manager to get a directory file descriptor It also checks if a directory doesn't contain a symlink in the path :param name: full directory name z/proc/self/fd/{}z%Operations on symlinks are prohibitedN)r" r O_DIRECTORYreadlinkformatPermissionError)r# r reals r open_dir_fdr* ) s r~ & &