HEX
Server: LiteSpeed
System: Linux kapuas.iixcp.rumahweb.net 5.14.0-427.42.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Nov 1 14:58:02 EDT 2024 x86_64
User: mirz4654 (1666)
PHP: 8.1.33
Disabled: system,exec,escapeshellarg,escapeshellcmd,passthru,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,popen,pclose,dl,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setsid,posix_setuid,posix_setpgid,ini_alter,show_source,define_syslog_variables,symlink,syslog,openlog,openlog,closelog,ocinumcols,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dll,ftp,myshellexec,socket_bind,mail,posix_getwpuid
Upload Files
File: //usr/lib/python3.9/site-packages/ansible/modules/__pycache__/unarchive.cpython-39.pyc
a

�)g'��@s$ddlmZmZmZeZdZdZdZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlmZddlmZmZddlmZmZmZdd	lmZdd
l m!Z!ddl"m#Z#ddl$m%Z%zdd
l&m'Z'Wn e(�ydd
l)m'Z'Yn0e�*d�Z+e�*d�Z,e�*d�Z-e�*d�Z.e�*d�Z/e�*d�Z0e�*d�Z1e�*d�Z2e�*d�Z3dd�Z4dd�Z5Gdd�de6�Z7Gdd�de8�Z9Gdd �d e8�Z:Gd!d"�d"e:�Z;Gd#d$�d$e:�Z<Gd%d&�d&e:�Z=Gd'd(�d(e:�Z>Gd)d*�d*e9�Z?d+d,�Z@d-d.�ZAeBd/k�r eA�dS)0�)�absolute_import�division�print_functiona�
---
module: unarchive
version_added: '1.4'
short_description: Unpacks an archive after (optionally) copying it from the local machine
description:
     - The C(unarchive) module unpacks an archive. It will not unpack a compressed file that does not contain an archive.
     - By default, it will copy the source file from the local system to the target before unpacking.
     - Set C(remote_src=yes) to unpack an archive which already exists on the target.
     - If checksum validation is desired, use M(ansible.builtin.get_url) or M(ansible.builtin.uri) instead to fetch the file and set C(remote_src=yes).
     - For Windows targets, use the M(community.windows.win_unzip) module instead.
options:
  src:
    description:
      - If C(remote_src=no) (default), local path to archive file to copy to the target server; can be absolute or relative. If C(remote_src=yes), path on the
        target server to existing archive file to unpack.
      - If C(remote_src=yes) and C(src) contains C(://), the remote machine will download the file from the URL first. (version_added 2.0). This is only for
        simple cases, for full download support use the M(ansible.builtin.get_url) module.
    type: path
    required: true
  dest:
    description:
      - Remote absolute path where the archive should be unpacked.
      - The given path must exist. Base directory is not created by this module.
    type: path
    required: true
  copy:
    description:
      - If true, the file is copied from local controller to the managed (remote) node, otherwise, the plugin will look for src archive on the managed machine.
      - This option has been deprecated in favor of C(remote_src).
      - This option is mutually exclusive with C(remote_src).
    type: bool
    default: yes
  creates:
    description:
      - If the specified absolute path (file or directory) already exists, this step will B(not) be run.
      - The specified absolute path (file or directory) must be below the base path given with C(dest:).
    type: path
    version_added: "1.6"
  io_buffer_size:
    description:
      - Size of the volatile memory buffer that is used for extracting files from the archive in bytes.
    type: int
    default: 65536
    version_added: "2.12"
  list_files:
    description:
      - If set to True, return the list of files that are contained in the tarball.
    type: bool
    default: no
    version_added: "2.0"
  exclude:
    description:
      - List the directory and file entries that you would like to exclude from the unarchive action.
      - Mutually exclusive with C(include).
    type: list
    default: []
    elements: str
    version_added: "2.1"
  include:
    description:
      - List of directory and file entries that you would like to extract from the archive. If C(include)
        is not empty, only files listed here will be extracted.
      - Mutually exclusive with C(exclude).
    type: list
    default: []
    elements: str
    version_added: "2.11"
  keep_newer:
    description:
      - Do not replace existing files that are newer than files from the archive.
    type: bool
    default: no
    version_added: "2.1"
  extra_opts:
    description:
      - Specify additional options by passing in an array.
      - Each space-separated command-line option should be a new element of the array. See examples.
      - Command-line options with multiple elements must use multiple lines in the array, one for each element.
    type: list
    elements: str
    default: ""
    version_added: "2.1"
  remote_src:
    description:
      - Set to C(true) to indicate the archived file is already on the remote system and not local to the Ansible controller.
      - This option is mutually exclusive with C(copy).
    type: bool
    default: no
    version_added: "2.2"
  validate_certs:
    description:
      - This only applies if using a https URL as the source of the file.
      - This should only set to C(false) used on personally controlled sites using self-signed certificate.
      - Prior to 2.2 the code worked as if this was set to C(true).
    type: bool
    default: yes
    version_added: "2.2"
extends_documentation_fragment:
- action_common_attributes
- action_common_attributes.flow
- action_common_attributes.files
- decrypt
- files
attributes:
    action:
      support: full
    async:
      support: none
    bypass_host_loop:
      support: none
    check_mode:
      support: partial
      details: Not supported for gzipped tar files.
    diff_mode:
      support: partial
      details: Uses gtar's C(--diff) arg to calculate if changed or not. If this C(arg) is not supported, it will always unpack the archive.
    platform:
      platforms: posix
    safe_file_operations:
      support: none
    vault:
      support: full
todo:
    - Re-implement tar support using native tarfile module.
    - Re-implement zip support using native zipfile module.
notes:
    - Requires C(zipinfo) and C(gtar)/C(unzip) command on target host.
    - Requires C(zstd) command on target host to expand I(.tar.zst) files.
    - Can handle I(.zip) files using C(unzip) as well as I(.tar), I(.tar.gz), I(.tar.bz2), I(.tar.xz), and I(.tar.zst) files using C(gtar).
    - Does not handle I(.gz) files, I(.bz2) files, I(.xz), or I(.zst) files that do not contain a I(.tar) archive.
    - Existing files/directories in the destination which are not in the archive
      are not touched. This is the same behavior as a normal archive extraction.
    - Existing files/directories in the destination which are not in the archive
      are ignored for purposes of deciding if the archive should be unpacked or not.
seealso:
- module: community.general.archive
- module: community.general.iso_extract
- module: community.windows.win_unzip
author: Michael DeHaan
au
- name: Extract foo.tgz into /var/lib/foo
  ansible.builtin.unarchive:
    src: foo.tgz
    dest: /var/lib/foo

- name: Unarchive a file that is already on the remote machine
  ansible.builtin.unarchive:
    src: /tmp/foo.zip
    dest: /usr/local/bin
    remote_src: yes

- name: Unarchive a file that needs to be downloaded (added in 2.0)
  ansible.builtin.unarchive:
    src: https://example.com/example.zip
    dest: /usr/local/bin
    remote_src: yes

- name: Unarchive a file with extra options
  ansible.builtin.unarchive:
    src: /tmp/foo.zip
    dest: /usr/local/bin
    extra_opts:
    - --transform
    - s/^xxx/yyy/
a_
dest:
  description: Path to the destination directory.
  returned: always
  type: str
  sample: /opt/software
files:
  description: List of all the files in the archive.
  returned: When I(list_files) is True
  type: list
  sample: '["file1", "file2"]'
gid:
  description: Numerical ID of the group that owns the destination directory.
  returned: always
  type: int
  sample: 1000
group:
  description: Name of the group that owns the destination directory.
  returned: always
  type: str
  sample: "librarians"
handler:
  description: Archive software handler used to extract and decompress the archive.
  returned: always
  type: str
  sample: "TgzArchive"
mode:
  description: String that represents the octal permissions of the destination directory.
  returned: always
  type: str
  sample: "0755"
owner:
  description: Name of the user that owns the destination directory.
  returned: always
  type: str
  sample: "paul"
size:
  description: The size of destination directory in bytes. Does not include the size of files or subdirectories contained within.
  returned: always
  type: int
  sample: 36
src:
  description:
    - The source archive's path.
    - If I(src) was a remote web URL, or from the local ansible controller, this shows the temporary location where the download was stored.
  returned: always
  type: str
  sample: "/home/paul/test.tar.gz"
state:
  description: State of the destination. Effectively always "directory".
  returned: always
  type: str
  sample: "directory"
uid:
  description: Numerical ID of the user that owns the destination directory.
  returned: always
  type: int
  sample: 1000
N)�partial)�ZipFile�
BadZipfile)�to_bytes�	to_native�to_text)�
AnsibleModule)�get_bin_path)�get_best_parsable_locale)�
fetch_file)�quotez: Uid differs$z: Gid differs$z: Mode differs$z: Mod time differs$z4: : Warning: Cannot stat: No such file or directory$z2: Warning: Cannot stat: No such file or directory$z([r-][w-][SsTtx-]){3}z: Invalid ownerz: Invalid groupcCs`t�d�}t|d��4}tt|j|�d�D]}t�||�}q(Wd�n1sN0Y|d@S)z# Return a CRC32 checksum of a file ��rbNl��)�binascii�crc32�open�iterr�read)�pathZbuffer_size�crc�fZb_block�r�=/usr/lib/python3.9/site-packages/ansible/modules/unarchive.pyrs

,rcCst�dd|�S)z6 Quote meta-characters in the args for the unix shell z([^A-Za-z0-9_])z\\\1)�re�sub)�stringrrr�shell_escape%src@seZdZdS)�UnarchiveErrorN)�__name__�
__module__�__qualname__rrrrr *sr c@sPeZdZdd�Zdd�Zdd�Zdd�Zed	d
��Zdd�Z	d
d�Z
dd�ZdS)�
ZipArchivecCsz||_||_||_|jd|_||_|jd|_|jd|_g|_|jjd|_	d|_
d|_g|_t
�|_d|_d|_dS)N�
extra_opts�io_buffer_size�exclude�include�)��unzip�cmd_path)�zipinfo�zipinfo_cmd_path)�src�b_dest�	file_args�params�opts�moduler&�excludes�includes�
include_filesr,r.�_files_in_archive�dict�	_infodict�zipinfoflag�binaries��selfr/r0r1r4rrr�__init__0szZipArchive.__init__cCsd|ddd�}d}tdd�D]<}tdd�D],}||d|dvr*|d|d|7}q*q||@S)zA Convert a Unix permission string (rw-r--r--) into a mode (0644) N���r�)�r�w�x�s�t�)�range)r>Zmodestr�umaskZrevstr�mode�j�irrr�_permstr_to_octalDszZipArchive._permstr_to_octalcCsz|j�|jd|jg�\}}}|r.td|j��|��dd�D]6}|�dd�}|j�|d�t	|d�|j
|d<q>dS)Nz-vz,Neither python zipfile nor unzip can read %srA�����)r4�run_commandr,r/r �
splitlines�splitr8�append�intr:)r>�rc�out�err�line�fieldsrrr�_legacy_file_listQszZipArchive._legacy_file_listc
Cs�|jr|j|Szt|j�}WnDtyb}z,|jd���d�rL|��n�WYd}~nRd}~00z$|��D]}t	|j
�|j|j<qnWn"ty�|�
�td��Yn0|j|S)Nr�bad magic numberz#Unable to list files in the archive)r:rr/r�args�lower�
startswithr[�infolistrUZCRC�filename�	Exception�closer )r>r�archive�e�itemrrr�_crc32[s

zZipArchive._crc32c
Cs4|jr|jSg|_zt|j�}WnDtyd}z,|jd���d�rN|��n�WYd}~n�d}~00z�|��D]r}|j	r�|j	D] }t
�
||�r�|j�t|��q�qpd}|j
r�|j
D]}t
�
||�r�d}q�q�|sp|j�t|��qpWn>t�y$}z$|��tdt|���WYd}~n
d}~00|��|jS)Nrr\FT�'Unable to list files in the archive: %s)r8rr/rr]r^r_r[Znamelistr7�fnmatchrTr	r5rbrcr )r>rdre�memberr(�exclude_flagr'rrr�files_in_archivers8


&zZipArchive.files_in_archivec,Cs2
|jr|j|jdd|jg}n|jdd|jg}|jrD|�dg|j�|jrV|�|j�|j�|�\}}}|}d}d}|dkr�d}nd}t�	d�}t�	|�t
��}	t��}
t�
�}t��}zt�|�j}
Wnttfy�|}
Yn0zt�|�j}Wntttf�y|}Yn0d}}|jd�r�zt�|jd�}WnRt�y�zt�t|jd��}Wn$tttf�y�t�|�}Yn0Yn0|j}|j}n"z|
}Wnt�y�Yn0|}d}}|jd	�rPzt�|jd	�}WnVttf�y@zt�t|jd	��}Wn$tttf�y:t�|�}Yn0Yn0|j}|j}n"z|}Wnt�ylYn0|}|� �D�]�}d}|�!dd
�}t"|�dk�r��qzt"|d�d
k�r�t"|d�dk�rʐqzt"|d
�dk�r�qz|dddv�szt#|ddd���$d��s�qz|dd}|ddd�}|d}|d}t|d�}t%|d
dd�}||jv�rv|d|7}�qz|ddk�r�|dk�r�|d||f7}d}n.|dk�r�d}n|dk�r�d}n|dk�r�d}t"|�d
k�r|ddk�r�d }n|d!k�rd }nd"}|}nd#|	�&�v�r"|}nd}t"|�d$k�s@t'�(|��sLt)d%|��tj*�+|j,t-|dd��} zt�.| �}!WnFt�y�d}|j/�0|�|d&|7}|d'||f7}Y�qzYn0|dk�rt1�2|!j3��sd}|j/�0|�|d(|7}|d)||f7}�qz|dk�rNt1�4|!j3��sNd}d}|j/�0|�|d*|7}|d)||f7}�qz|dk�r�t1�5|!j3��s�d}|j/�0|�|d+|7}|d)||f7}�qzt6d,|�}"t7j7t8�9|d
d-�dd
��}#t8�:|#�;��}$t1�4|!j3��r�|jj<d.�rT|$|!j=k�rd}|j/�0|�|d/|7}d0|"d1<n6t1�4|!j3��r�|$|!j=k�r�|d2|7}|j�0|��qzn8|$|!j=k�r�d}|j/�0|�|d3||$|!j=f7}d0|"d1<t1�4|!j3��r�||!j>k�r�d}|d4|||!j>f7}d5|"d<t1�4|!j3��rt?| |j@�}%|%|�A|�k�rd}|d6||�A|�|%f7}d7|"d<|dk�r>|jd8�r�tB|jd8t��rH|jd8}&n�zt|jd8d�}&Wn�t�y�}'zhztC�D|!|jd8�}&WnDt�y�}'z*|jjE|d9tF|'�tG�H�d:�WYd}'~'n
d}'~'00WYd}'~'n
d}'~'00n$|dk�r�|�I|d�}&n|�I||�}&|&t1�J|!j3�k�r>d}d;|"d<<|d=||&t1�J|!j3�f7}d}(})zt�|!jK�j}(Wnttf�yv|!jK})Yn0|dk�r�||
k�s�||k�r�t)d>|||
f��|(�r�|(|k�r�d}|d?||(|f7}d@|"d
<n.|)�	r|)|k�	rd}|dA||)|f7}d@|"d
<d}*}+zt�|!jL�j}*Wn tttf�	y@|!jL}+Yn0|dk�	r|||k�	s`||k�	r|||
v�	r|t)dB|||
f��|*�	r�|*|k�	r�d}|dC||*|f7}dD|"d
<n.|+�	r�|+|k�	r�d}|dE||+|f7}dD|"d
<|�rz||j/v�	r�|j/�0|�|dFd�+|"�|f7}�qz|j/�
rd}tM||||||dG�S)HNz-Tz-s�-xr)rTF�owner�grouprO��
rP�zdl-?�zrwxstah-rGrA�surrogate_or_strict��errorszPath %s is excluded on request
r@�/�dz8Path %s incorrectly tagged as "%s", but is a directory.
�l�L�-r�?Z	rwxrwxrwxzrwx---z	rw-rw-rw-�bsd�	z"ZIP info perm format incorrect, %szPath %s is missing
z>%s++++++.?? %s
z/File %s already exists, but not as a directory
zc%s++++++.?? %s
z7Directory %s already exists, but not as a regular file
z2Directory %s already exists, but not as a symlink
z.%s.......??z
%Y%m%d.%H%M%S�
keep_newerz!File %s is older, replacing file
rF�z!File %s is newer, excluding file
z$File %s differs in mtime (%f vs %f)
z#File %s differs in size (%d vs %d)
rEz5File %s differs in CRC32 checksum (0x%08x vs 0x%08x)
�crJz%s)r�msg�	exception�p�z*Path %s differs in permissions (%o vs %o)
z/Cannot change ownership of %s to %s, as user %sz8Path %s is owned by user %s, not by user %s as expected
�oz6Path %s is owned by uid %s, not by uid %s as expected
z5Cannot change group ownership of %s to %s, as user %sz:Path %s is owned by group %s, not by group %s as expected
�gz6Path %s is owned by gid %s, not by gid %s as expected
z%s %s
)�
unarchivedrVrWrX�cmd�diff)Nr;r.r/r5�extendr7r4rQ�osrI�platform�system�	getgroups�getuid�getgid�pwd�getpwuid�pw_name�	TypeError�KeyError�grp�getgrgid�gr_name�
ValueError�
OverflowErrorr1�getpwnamrU�pw_uidrb�getgrnam�gr_gidrRrS�len�	frozenset�issubsetr
r^�ZIP_FILE_MODE_RE�matchr r�joinr0r�lstatr6rT�stat�S_ISDIR�st_mode�S_ISREG�S_ISLNK�list�datetime�time�strptime�mktimeZ	timetupler2�st_mtime�st_sizerr&rg�
isinstancerZ_symbolic_mode_to_octal�	fail_jsonr	�	traceback�
format_excrM�S_IMODE�st_uid�st_gidr9),r>r�rVrWrX�old_outr�r�rIZ
systemtype�groups�run_uidZrun_gidZ	run_ownerZ	run_groupZ	fut_ownerZfut_uidZtpwZ	fut_groupZfut_gidZtgrrYZchangeZpcsZztypeZpermstr�versionZostype�sizerZftypeZ
file_umaskr0�stZitemizedZ	dt_objectZ	timestamprrJrern�uidro�gidrrr�
is_unarchived�s�



$.



	


L

(
zZipArchive.is_unarchivedcCs�|jdg}|jr|�|j�|�|j�|jr@|�dg|j�|jrR|�|j�|�d|jg�|j�	|�\}}}t
||||d�S)Nz-ormz-d�r�rVrWrX)r,r3r�rTr/r5r7r0r4rQr9)r>r�rVrWrXrrr�	unarchive�s
zZipArchive.unarchivec	Cs�g}|jD]B}zt||dt|d��Wq
tyJ|�|d�Yq
0q
|rhddjd�|�d�fS|jd|jg}|j	�
|�\}}}|dkr�dSdd	|j|ffS)
NrsrFz7Unable to find required '{missing}' binary in the path.z' or ')�missingz-l�TN�)Command "%s" could not handle archive: %s)r<�setattrrr�rT�formatr�r,r/r4rQ)r>r��br�rVrWrXrrr�can_handle_archive�s
zZipArchive.can_handle_archiveN)r!r"r#r?rMr[rg�propertyrlr�r�r�rrrrr$.s


%6r$c@s@eZdZdd�Zdd�Zedd��Zdd�Zd	d
�Zdd�Z	d
S)�
TgzArchivecCs�||_||_||_|jd|_||_|jjrD|jjdd|jjd�dd�|jjdD�|_	|jjd|_
d|_d|_d	|_
g|_dS)
Nr%Tz>remote module (%s) does not support check mode when using gtar)Zskippedr�cSsg|]}|�d��qS)rw)�rstrip)�.0rrrr�
<listcomp>�rz'TgzArchive.__init__.<locals>.<listcomp>r'r(z-z)r/r0r1r2r3r4�
check_mode�	exit_json�_namer5r7r,�tar_type�zipflagr8r=rrrr?�szTgzArchive.__init__cCsJ|jdg}|j�|�\}}}d}|�d�r0d}n|�d�rFd|vrFd}|S)Nz	--versionZbsdtarr}�tarZGNU�gnu)r,r4rQr_)r>r�rVrWrXr�rrr�
_get_tar_types

zTgzArchive._get_tar_typec		CsJ|jr|jS|jdd|jg}|jr.|�|j�|jrF|�dg|j�|jrb|�dd�|jD��|�d|jg�|j	r�|�|j	�t
|j�}|jj||jt
||||d�d�\}}}|d	kr�td
|��|��D]r}tt�|�d	�}|�d�r�|dd�}d
}|j�r.|jD]}t�||��rd}�q.�q|s�|j�t|��q�|jS)Nz--list�-C�--show-transformed-namescSsg|]}d|�qS�z
--exclude=r�r�rrrrr�rz/TgzArchive.files_in_archive.<locals>.<listcomp>�-f��LANG�LC_ALL�LC_MESSAGES�LANGUAGE��cwdZenviron_updaterrhrwrsFT)r8r,r0r�rTr3r�r5r/r7r
r4rQr9r rRr	�codecs�
escape_decoder_ri)	r>r��localerVrWrXrarkr'rrrrl
s:
&


zTgzArchive.files_in_archivec
	Cs:|jdd|jg}|jr"|�|j�|jr:|�dg|j�|jdr\|�dt|jd��|jdr~|�dt|jd��|jj	dr�|�d	�|j
r�|�d
d�|j
D��|�d|jg�|jr�|�|j�t
|j�}|jj||jt||||d
�d�\}}}d}|}d}t��}|��|��D]�}	t�|	��r:�q&|dk�rh|jd�sht�|	��rh||	d7}|dk�r�|jd�s�t�|	��r�||	d7}|jd�s�t�|	��r�||	d7}t�|	��r�||	d7}t�|	��r�||	d7}t�|	��r||	d7}t�|	��r&||	d7}�q&|�r(d}t|||||d�S)Nz--diffr�r�rn�--owner=ro�--group=r�--keep-newer-filescSsg|]}d|�qSr�rr�rrrr�Crz,TgzArchive.is_unarchived.<locals>.<listcomp>r�r�r�Tr)r�
rJF)r�rVrWrXr�)r,r0r�rTr3r�r1rr4r2r5r/r7r
rQr9r�r�rR�
EMPTY_FILE_RE�search�
OWNER_DIFF_RE�
GROUP_DIFF_RE�MODE_DIFF_RE�MOD_TIME_DIFF_RE�MISSING_FILE_RE�INVALID_OWNER_RE�INVALID_GROUP_RE)
r>r�r�rVrWrXr�r�r�rYrrrr�6sT



&""zTgzArchive.is_unarchivedc	Cs|jdd|jg}|jr"|�|j�|jr:|�dg|j�|jdr\|�dt|jd��|jdr~|�dt|jd��|jj	dr�|�d	�|j
r�|�d
d�|j
D��|�d|jg�|jr�|�|j�t
|j�}|jj||jt||||d
�d�\}}}t||||d�S)Nz	--extractr�r�rnr�ror�rr�cSsg|]}d|�qSr�rr�rrrr�yrz(TgzArchive.unarchive.<locals>.<listcomp>r�r�r�r�)r,r0r�rTr3r�r1rr4r2r5r/r7r
rQr9)r>r�r�rVrWrXrrrr�ls&



&zTgzArchive.unarchivecCs�ztd�|_Wn8tyFztd�|_Wnty@YYdS0Yn0|��|_|jdkrpdd|j|jffSz|jr~WdSWn:ty�}z"dd|jt|�ffWYd}~Sd}~00dd	|jfS)
NZgtarr�)Fz:Unable to find required 'gtar' or 'tar' binary in the pathr�Fz7Command "%s" detected as tar type %s. GNU tar required.r�r�zNCommand "%s" found no files in archive. Empty archive files are not supported.)rr,r�r�r�rlr r	)r>rerrrr��s 


,zTgzArchive.can_handle_archiveN)
r!r"r#r?r�r�rlr�r�r�rrrrr��s

+6r�cseZdZ�fdd�Z�ZS)�
TarArchivecs tt|��||||�d|_dS)Nr))�superr�r?r�r=��	__class__rrr?�szTarArchive.__init__�r!r"r#r?�
__classcell__rrr�rr��sr�cseZdZ�fdd�Z�ZS)�TarBzipArchivecs tt|��||||�d|_dS)Nz-j)r�r�r?r�r=r�rrr?�szTarBzipArchive.__init__r�rrr�rr��sr�cseZdZ�fdd�Z�ZS)�TarXzArchivecs tt|��||||�d|_dS)Nz-J)r�r�r?r�r=r�rrr?�szTarXzArchive.__init__r�rrr�rr��sr�cseZdZ�fdd�Z�ZS)�TarZstdArchivecs tt|��||||�d|_dS)Nz--use-compress-program=zstd)r�r�r?r�r=r�rrr?�szTarZstdArchive.__init__r�rrr�rr��sr�cs(eZdZ�fdd�Z�fdd�Z�ZS)�ZipZArchivecs&tt|��||||�d|_d|_dS)Nz-Z)r*)r+r.)r�r�r?r;r<r=r�rrr?�szZipZArchive.__init__csXtt|���\}}|s||fS|j|jg}|j�|�\}}}d|��vrLdSdd|fS)Nr-r�Fz/Command "unzip -Z" could not handle archive: %s)r�r�r�r.r;r4rQr^)r>Zunzip_availableZ	error_msgr�rVrWrXr�rrr��szZipZArchive.can_handle_archive)r!r"r#r?r�r�rrr�rr��sr�cCsttttttttg}t�}|D]4}|||||�}|��\}}	|rF|S|�	|	�qd�
|�}
|jd||
fd�dS)Nr�zdFailed to find handler for "%s". Make sure the required command to extract the file is installed.
%s�r�)r$r�r�r�r�r�r��setr��addr�r�)r/�destr1r4�handlersZreasons�handler�objZ
can_handle�reasonZ
reason_msgrrr�pick_handler�s
rcCs,tttddd�tddd�tddd�tdd�tddd�tddd�tdd	gd
�tdd	gd
�tdd	gd
�tddd�tddd�tddd�tddd�d
�
dddgd�}|jd}|jd}t|dd�}|jd}|�|j�}tj�|��s|s�|jd|d�n&d|v�rt	||�}n|jd|d�t�
|tj��s<|jd|d�z&tj�|�dk�r`|jd|d�Wn>t
�y�}z$|jd|t|�fd�WYd}~n
d}~00tj�|��s�|jd|d�t||||�}t|jj||d�}|��}	|j�r|	d|d <n�|	d�rd|d <nxz>|��|d!<|d!d"dk�rP|jfd#d$||fi|��Wn0t�y�|jfd#d$||fi|��Yn
0d|d <|	�d%d��r�d&|	d%i|d%<|�d%d��r|j�sg}
|jD]�}tj�|t|dd��|d<z|j||d dd'�|d <WnFttf�yJ}z(|jfd#d(t|�i|��WYd}~n
d}~00d)|v�r�|�d)�d}||
v�r�|
�|��q�|
�r|
D]z}
d*||
f|d<z|j||d dd'�|d <WnFttf�y�}z(|jfd#d(t|�i|��WYd}~n
d}~00�q�|jd+�r|j|d,<|jfi|��dS)-NrT)�type�required�boolF)r�default)rr��str)r�elementsrrUi)
r/r�
remote_srcZcreates�
list_filesrr'r(r%Zvalidate_certsr&�copyZdecrypt)r(r')Z
argument_specZadd_file_common_argsZsupports_check_modeZmutually_exclusiver/rrtrurzSource '%s' failed to transferr�z://zSource '%s' does not existzSource '%s' not readablerz)Invalid archive '%s', the file is 0 byteszSource '%s' not readable, %sz#Destination '%s' is not a directory)rrr/r�ZchangedZextract_resultsrVr�zfailed to unpack %s to %sr�Zprepared)�expandz1Unexpected error when accessing exploded file: %srwz%s/%sr�files)rr9r2rZload_file_common_argumentsr�r�existsr�r�access�R_OK�getsizerbr	�isdirrr�r!r�r�r��IOError�getrlr�Zset_fs_attributes_if_different�OSErrorrSrTr�)r4r/rr0rr1rerZres_argsZ
check_resultsZtop_foldersraZtop_folder_pathrrrr�main�s�








��



.

 "
2

6
r�__main__)CZ
__future__rrrrZ
__metaclass__Z
DOCUMENTATIONZEXAMPLESZRETURNrr�r�rir�r�r�r�rr�r�r��	functoolsr�zipfilerrZansible.module_utils._textrr	r
Zansible.module_utils.basicrZ#ansible.module_utils.common.processrZ"ansible.module_utils.common.localer
Zansible.module_utils.urlsrZshlexr�ImportErrorZpipes�compiler�r�r�r�r�r�r�r�r�rrrbr �objectr$r�r�r�r�r�r�rrr!rrrr�<module>
sn<









D.
w