
    +                         d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlZddlZddl	Z	ddl
mc mc mZ ddlZ	 ddlZe	j                   ZddZd Zy# e$ r e	j&                  ZY w xY w)	z+Set of utilities for dealing with archives.    )absolute_import)division)unicode_literalsNc                 >   |d }t        j                  | dt              }	 t        j                  t        j                  |            D ]  \  }}}t        j                  j                  t        j                  j                  ||            } ||      sM|t        j                  k7  rt        |||d       |D ]9  }t        j                  j                  ||      }	 ||	      s,t        |||	d       ;  	 |j                          y# |j                          w xY w)a  Create a ZIP archive from a directory.

  This is similar to shutil.make_archive. However, prior to Python 3.8,
  shutil.make_archive cannot create ZIP archives for files with mtimes older
  than 1980. So that's why this function exists.

  Examples:
    Filesystem:
    /tmp/a/
    /tmp/b/B

    >>> MakeZipFromDir('my.zip', '/tmp')
    Creates zip with content:
    a/
    b/B

  Note this is caller responsibility to use appropriate platform-dependent
  path separator.

  Note filenames containing path separator are supported.

  Args:
    dest_zip_file: str, filesystem path to the zip file to be created. Note that
      directory should already exist for destination zip file.
    src_dir: str, filesystem path to the directory to zip up
    predicate: callable, takes one argument (file path). File will be included
               in the zip if and only if the predicate(file_path). Defaults to
               always true.
  Nc                      y)NT )xs    'lib/googlecloudsdk/core/util/archive.py<lambda>z MakeZipFromDir.<locals>.<lambda>G   s    $    wFT)zipfileZipFile_ZIP_COMPRESSIONoswalksix	text_typepathnormpathrelpathcurdirAddToArchivejoinclose)
dest_zip_filesrc_dir	predicatezip_fileroot_filelistdir_path	file_name	file_paths
             r
   MakeZipFromDirr&   '   s    > I__]C1AB(WWS]]7%;<a!!"''//$"@Ahx 	RYY	Xw%8)GGLL95	#
Xw	48	   = NNHNNs   CD
 
Dc                 ,   t         j                  j                  ||      }t         j                  j                  |      }t	        j
                  |      d   dk  r|rjt        j                         \  }}t        j                  |       t        j                  ||       | j                  ||       t        j                  |       yt        j                         5 }| j                  ||       ddd       y| j                  ||       y# 1 sw Y   yxY w)af  Add a file or directory (without its contents) to a ZIP archive.

  Args:
    zip_file: the ZIP archive
    src_dir: the base directory for rel_path, will not be recorded in the
      archive
    rel_path: the relative path to the file or directory to add
    is_file: a Boolean indicating whether rel_path points to a file (rather than
      a directory)
  r   i  N)r   r   r   getmtimetimegmtimetempfilemkstempr   shutilcopyfilewriteremovefilesTemporaryDirectory)	r   r   rel_pathis_file	full_pathmtimetemp_file_handletemp_file_pathtemp_dirs	            r
   r   r   Y   s     ggll7H-)
''

9
%%	[[T! )1)9)9);&hh ooi0nn^X.ii##%x* &% NN9h' &%s   D

D)N)__doc__
__future__r   r   r   r   r-   r+   r)   r   googlecloudsdk.core.util.filescoreutilr1   r   zlibZIP_DEFLATEDr   ImportError
ZIP_STOREDr&   r   r   r   r
   <module>rC      sj     2 &  ' 	     . . 
( ))
/d(m  (''(s   A A&%A&