
                             S r SSKJr  SSKJr  SSKJr  SSKrSSKJr  SSKJr  SSKJ	r	  SS	KJ
r
  SS
KJr  SSKJr  Sr  SS jr   SS jrS rS rg)z4Utility functions for performing download operation.    )absolute_import)division)unicode_literalsN)errors)	gzip_util)	hash_util)storage_url)symlink_util)tracker_file_util_symc                     [         R                  R                  U5      (       d  g[        R                  " U UUUU5      (       a  [         R
                  " U5        g[         R                  " X5        g)a  Converts temporary file to final form by decompressing or renaming.

Args:
  source_resource (ObjectResource): May contain encoding metadata.
  temporary_file_path (str): File path to unzip or rename.
  final_file_path (str): File path to write final file to.
  do_not_decompress_flag (bool): User flag that blocks decompression.
  server_encoding (str|None): Server-reported `content-encoding` of file.

Returns:
  (bool) True if file was decompressed or renamed, and
    False if file did not exist.
FT)ospathexistsr   decompress_gzip_if_necessaryremoverenamesource_resourcetemporary_file_pathfinal_file_pathdo_not_decompress_flagserver_encodings        @lib/googlecloudsdk/command_lib/storage/tasks/cp/download_util.py_decompress_or_rename_filer   !   sb    ( 
+	,	,++O,?,;,B,;	= =
 II!" 
 II!3	    c                     U=(       a    U R                   nU(       a
  U[        -   nOUn[        U UUUUS9nU(       d  gU(       a*  [        R                  " XrS9  [
        R                  " U5        U$ )a  Converts temporary file to final form.

This may involve decompressing, renaming, and/or converting symlink
placeholders to actual symlinks.

Args:
  source_resource (ObjectResource): May contain encoding metadata.
  temporary_file_path (str): File path to unzip or rename.
  final_file_path (str): File path to write final file to.
  do_not_decompress_flag (bool): User flag that blocks decompression.
  server_encoding (str|None): Server-reported `content-encoding` of file.
  convert_symlinks (bool): Whether symlink placeholders should be converted to
    actual symlinks.

Returns:
  (bool) True if file was decompressed, renamed, and/or converted to a
    symlink; False if file did not exist.
r   F)placeholder_pathsymlink_path)
is_symlink$SYMLINK_TEMPORARY_PLACEHOLDER_SUFFIXr   r
   )create_symlink_from_temporary_placeholderr   r   )	r   r   r   r   r   convert_symlinksmake_symlinkdecompress_or_rename_pathdecompress_or_rename_results	            r   finalize_downloadr'   C   s{    4 "@o&@&@, "5!E"F !0 :%-/3%! 
%::2 II'(	$$r   c                      [         R                  " XU5        g! [        R                   aB    [        R
                  " U 5        [        R                  " [        R                  " U 5      5        e f = f)zConfirms hashes match for copied objects.

Args:
  download_path (str): URL of object being validated.
  source_hash (str): Hash of source object.
  destination_hash (str): Hash of downloaded object.

Raises:
  HashMismatchError: Hashes are not equal.
N)
r   validate_object_hashes_matchr   HashMismatchErrorr   r   r   delete_download_tracker_filesr	   storage_url_from_string)download_pathsource_hashdestination_hashs      r   /validate_download_hash_and_delete_corrupt_filesr0   w   sZ    
**=+;=		!	! 
IIm33++M:<		
s
    AA0c                 D    U R                   S:X  a  U(       a  U" S5        gg)z>Returns valid download range bool and reports progress if not.r   TF)size)cloud_resourceprogress_callbacks     r   (return_and_report_if_nothing_to_downloadr5      s!    A	r   )FN)FNF)__doc__
__future__r   r   r   r   "googlecloudsdk.command_lib.storager   r   r   r	   r
   r   r!   r   r'   r0   r5    r   r   <module>r:      sW    ; &  ' 	 5 8 8 : ; @'- $ !L !1%h
,r   