
    +                         S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSKrSSKrSSK	r	SSK
Js  Js  Jr  SSKr SSKr\	R                   rSS jrS rg! \ a    \	R&                  r Nf = f)	z+Set of utilities for dealing with archives.    )absolute_import)division)unicode_literalsNc                 \   Uc  S n[         R                  " U S[        5      n [        R                  " [
        R                  " U5      5       H  u  pEn[        R                  R                  [        R                  R                  XA5      5      nU" U5      (       d  MQ  U[        R                  :w  a  [        X1US5        U H>  n[        R                  R                  Xx5      n	U" U	5      (       d  M1  [        X1U	S5        M@     M     UR                  5         g! UR                  5         f = f)az  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                     g)NT )xs    'lib/googlecloudsdk/core/util/archive.py<lambda> 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%;<!!"''//$"@Ahx  	RYY	X%8)GGLL5	##
X	48	   = NNHNNs   C$D D+c                 B   [         R                  R                  X5      n[         R                  R                  U5      n[        R
                  " U5      S   S:  a  U(       ak  [        R                  " 5       u  pg[         R                  " U5        [        R                  " XG5        U R                  Xr5        [         R                  " U5        g[        R                  " 5        nU R                  X5        SSS5        gU R                  XB5        g! , (       d  f       g= f)aV  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     ggll7-)
''

9
%%	[[T! )1)9)9);&hh ooi0nn^.ii##%x* &% NN9' &%s   #D
D)N)__doc__
__future__r   r   r   r   r.   r,   r*   r   googlecloudsdk.core.util.filescoreutilr2   r   zlibZIP_DEFLATEDr   ImportError
ZIP_STOREDr'   r   r   r   r
   <module>rD      sj     2 &  ' 	     . . 
( ))
/d(m  (''(s   A A('A(