Ë
    €Ïä  ã                   óˆ   — d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlm	Z	 ddl
mZ dd	lmZ d
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zy)z'Symlink utilities for storage commands.é    )Úabsolute_import)Údivision)Úunicode_literalsN)Útracker_file_util)Úresource_util)Ú
properties)Úfilesc                 óx   — |rd| t         j                  <   yt         j                  | v r| t         j                  = yy)z/Updates custom metadata_dict with symlink data.ÚtrueN)r   ÚSYMLINK_METADATA_KEY)Úmetadata_dictÚ
is_symlinks     ú6lib/googlecloudsdk/command_lib/storage/symlink_util.pyÚ3update_custom_metadata_dict_with_symlink_attributesr      s8   € ñ Ø8>€M”-×4Ñ4Ò5Ü×)Ñ)¨]Ñ:Ø”m×8Ñ8Ñ9ð ;ó    c                  ó”   — t         j                  j                  j                  j	                  «       } t        j                  | «       | S )z«Looks up or creates the gcloud storage symlink file directory.

  Symlink placeholder files will be kept here.

  Returns:
    The path string to the symlink directory.
  )r   ÚVALUESÚstorageÚsymlink_placeholder_directoryÚGetr	   ÚMakeDir)Úsymlink_directorys    r   Ú#_create_symlink_directory_if_neededr   '   s<   € ô ×Ñ×Ñ×=Ñ=×AÑAÓCð ô ‡--Ð!Ô"Ø	Ðr   c                 óÐ   — t        «       }t        j                  t        j                  | «      «      }t        j                  |«       t
        j                  j                  ||«      S )zEReturns a path suitable for storing a placeholder file for a symlink.)r   r   Úget_hashed_file_nameÚget_delimiterless_file_pathÚraise_exceeds_max_length_errorÚosÚpathÚjoin)Úsource_pathr   Úsymlink_filenames      r   Úget_symlink_placeholder_pathr#   7   sR   € ä9Ó;ÐÜ&×;Ñ;Ü×3Ñ3°KÓ@óÐô ×2Ñ2Ð3CÔDÜ	‰‰Ð'Ð)9Ó	:Ð:r   c                 óØ   — t        | «      }t        j                  |«      5 }|j                  t	        j
                  | «      j                  d«      «       ddd«       |S # 1 sw Y   |S xY w)aµ  Creates a placholder file for the given symlink.

  The placeholder will be created in the directory specified by the
  symlink_placeholder_directory property, and its content will be the path
  targeted by the given symlink.

  Args:
    source_path: The path to an existing symlink for which a placeholder should
      be created.

  Returns:
    The path to the placeholder file that was created to represent the given
    symlink.
  zutf-8N)r#   r	   ÚBinaryFileWriterÚwriter   ÚreadlinkÚencode)r!   Úplaceholder_pathÚplaceholder_writers      r   Úget_symlink_placeholder_filer+   A   sZ   € ô 2°+Ó>ÐÜ×ÑÐ.Ô/Ð3EØ×ÑœRŸ[™[¨Ó5×<Ñ<¸WÓEÔF÷ 0à	Ð÷ 0à	Ðús   ¡4AÁA)c                 óZ   — t        j                  | «      }t        j                  ||«       y ©N)r	   ÚReadFileContentsr   Úsymlink)r)   Úsymlink_pathÚsymlink_targets      r   Ú)create_symlink_from_temporary_placeholderr2   V   s!   € Ü×)Ñ)Ð*:Ó;€.Ü‡**ˆ^˜\Õ*r   c                 ó"   — | r| j                   S d S r-   )Úpreserve_symlinks)Úuser_request_argss    r   Ú&get_preserve_symlink_from_user_requestr6   [   s   € Ù0AÐ	×	,Ñ	,ÐKÀtÐKr   )Ú__doc__Ú
__future__r   r   r   r   Ú"googlecloudsdk.command_lib.storager   Ú,googlecloudsdk.command_lib.storage.resourcesr   Úgooglecloudsdk.corer   Úgooglecloudsdk.core.utilr	   r   r   r#   r+   r2   r6   © r   r   Ú<module>r>      sA   ðñ .å &Ý Ý 'ã 	å @Ý FÝ *Ý *ò:òò ;òò*+ó
Lr   