File: //proc/1233/root/usr/lib/python3/dist-packages/docker/utils/__pycache__/build.cpython-310.pyc
o
�2.a � @ s� d dl Z d dlZd dlZd dlZd dlZddlmZ ddlmZ er'e�d�ne�d�Z dd d
�Z
ddd�Zd
d� Z d dd�Z
dd� Zdd� Zdd� Zd!dd�ZG dd� d�ZG dd� d�ZdS )"� N� )�fnmatch� )�IS_WINDOWS_PLATFORMz/|\\�/Fc C sv t j�| �}|p g }|p
d}g }|d d ur)d�|pdg|d g �}d|f|g}ttt|||d d��||||d�S )N)NNr �
z
.dockerignorer )�
dockerfile)�files�root�fileobj�gzip�extra_files)�os�path�abspath�join�create_archive�sorted�
exclude_paths)r �excluder r r r
r
�dockerignore_contents� r �4/usr/lib/python3/dist-packages/docker/utils/build.py�tar s ���r c C s0 |du rd}|� d| � t|�}t|�| ��S )a
Given a root directory path and a list of .dockerignore patterns, return
an iterator of all paths (both regular files and directories) in the root
directory that do *not* match any of the patterns.
All paths returned are relative to the root.
N�
Dockerfile�!)�append�PatternMatcher�set�walk)r
�patternsr �pmr r r r ! s
r c C sT g }t �| �D ] \}}}|| D ]}t j�||�}|�|�| dd��d�� qq|S )N� r r )r r r r r �replace�lstrip)r
r �dirname�dirnames�fnames�filename�longpathr r r �build_file_list2 s ��r* c C sv |pg }|s
t �� }tj|rdnd|d�}|d u rt| �}dd� |D �}|D ]j}||v r-q&tj�| |�}|j||d�} | d u r@q&| j dk sJ| j dkrPt
| j �| _ trZ| jd @ d
B | _| �
� r�zt|d��}
|�| |
� W d � n1 suw Y W q& ty� td|� ���w |�| d � q&|D ]\}}t�|�}
|�d
�}t|�|
_|�|
t�|�� q�|�� |�d� |S )Nzw:gz�w��moder c S s h | ]}|d �qS )r r )�.0�er r r � <setcomp>F � z!create_archive.<locals>.<setcomp>)�arcnamer l �� i� �I �rbzCan not read file in context: zutf-8)�tempfile�NamedTemporaryFile�tarfile�openr* r r r �
gettarinfo�mtime�intr r- �isfile�addfile�OSError�TarInfo�encode�len�size�io�BytesIO�close�seek)r
r r r r
�t�extra_namesr � full_path�i�f�name�contents�info�contents_encodedr r r r >