관리-도구
편집 파일: filesystem.cpython-38.pyc
U &?�fV � @ sP d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZ d dl m Z mZmZm Z mZmZ d dlmZ d dlmZ d dlmZ eed�d d �Zeee eeddf d�dd ��Zeddd�ej�Zeed�dd�Zeed�dd�Zeee e d�dd�Zeeeef d�dd�Z eed�dd�Z!eeeef d�dd�Z"eed�dd�Z#dS ) � N)�contextmanager)�NamedTemporaryFile)�Any�BinaryIO� Generator�List�Union�cast)�get_path_uid)�format_size)�retry)�path�returnc C s� t jdksttd�sdS tj�| �s(t�d }| |kr�tj�| �r�t�� dkrxzt | �}W n t k rn Y dS X |dkS t�| tj�S q,| tj� | � }} q,dS )N�win32�geteuidTr F)�sys�platform�hasattr�osr �isabs�AssertionError�lexistsr r �OSError�access�W_OK�dirname)r �previous�path_uid� r �L/opt/hc_python/lib/python3.8/site-packages/pip/_internal/utils/filesystem.py�check_path_owner s r )r �kwargsr c k sf t f dtj�| �tj�| �dd�|���4}tt|�}z |V W 5 |�� t�|� � � X W 5 Q R X dS )a% Return a file-like object pointing to a tmp file next to path. The file is created securely and is ensured to be written to disk after the context reaches its end. kwargs will be passed to tempfile.NamedTemporaryFile to control the way the temporary file will be opened. Fz.tmp)�delete�dir�prefix�suffixN) r r r r �basenamer r �flush�fsync�fileno)r r! �f�resultr r r �adjacent_tmp_file* s �� r, � g �?)�stop_after_delay�waitc C sH t j�| �s(t j�| �}|| kr"q(|} q t jdkr@t �| t j�S t| �S )zgCheck if a directory is writable. Uses os.access() on POSIX, tries creating files on Windows. �posix)r r �isdirr �namer r �_test_writable_dir_win)r �parentr r r �test_writable_dirH s r5 c s� d}d� t d�D ]�}|d�� fdd�t d�D �� }tj�| |�}zt�|tjtjB tjB �}W n* tk rt Y q t k r� Y dS X t� |� t�|� d S qtd ��d S )N�(accesstest_deleteme_fishfingers_custard_�$abcdefghijklmnopqrstuvwxyz0123456789� � c 3 s | ]}t �� �V qd S �N)�random�choice)�.0�_��alphabetr r � <genexpr>` s z)_test_writable_dir_win.<locals>.<genexpr>� FTz3Unexpected condition testing for writable directory) �range�joinr r �open�O_RDWR�O_CREAT�O_EXCL�FileExistsError�PermissionError�close�unlinkr )r r&