+
    jHàj  ã                  ó’   € R t ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RI	H
t
HtHt R R ltR R ltR	 R
 ltR R ltR R ltR# )zKSafe ``tar.gz`` primitives shared by the profile and kanban transfer paths.)ÚannotationsN)Úsuppress)ÚPathÚPurePosixPathÚPureWindowsPathc               ó    € V ^8„  d   QhRRRR/# )é   Úmember_nameÚstrÚreturnz	list[str]© )Úformats   "Ú</home/ubuntu/.hermes/hermes-agent/hermes_cli/archive_safe.pyÚ__annotate__r      s   € ÷ ñ ¨ð °ñ ó    c                ól  € V P                  RR4      p\        V4      p\        V 4      pVP                   Uu. uF  qDR9  g   K  VNK  	  ppV'       dN   VP	                  4       '       g8   VP	                  4       '       g"   VP
                  '       g   V'       d   RV9   d   \        RV  24      hV# u upi )a(  Return safe path parts for an archive member, or raise ``ValueError``.

Rejects absolute paths (POSIX and Windows, including drive letters), empty names, and any ``..``
component. Backslashes are folded to ``/`` first so a Windows-authored archive can't smuggle a
separator past the POSIX parse.
Ú\Ú/z..zUnsafe archive member path: >   Ú Ú.)Úreplacer   r   ÚpartsÚis_absoluteÚdriveÚ
ValueError)r	   Únormalized_nameÚ
posix_pathÚwindows_pathÚpartr   s   &     r   Únormalize_archive_partsr      sž   € ð "×)Ñ)¨$°Ó4€OÜ˜Ó/€JÜ" ;Ó/€LØ(×.Ò.ÓHÑ.�d¸iÑ2G�TˆTÑ.€EÐHß˜z×5Ñ5×7Ò7¸<×;SÑ;S×;UÒ;UØ×!×!Ð!¯°$¸%´-ÜÐ7¸°}ÐEÓFÐFØ€Lùò	 Is   ·B1ÁB1c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   Úbaser
   Úroot_dirÚbase_dirr   r   )r   s   "r   r   r      s(   € ÷ ñ �Sð  Cð °3ð ¸3ñ r   c                óÜ  € V  R2p\         P                  P                  V4      ;'       g    Rp\        P                  ! VRRR7      w  rV \         P
                  ! VR4      ;_uu_ 4       p\        P                  ! VR\        P                  R7      ;_uu_ 4       pVP                  \        \        V4      V,          4      VR	7       R
R
R
4       R
R
R
4       \         P                  ! Wc4       V#   + '       g   i     L0; i  + '       g   i     L;; i  \         dL    \        \        4      ;_uu_ 4        \         P                   ! T4       R
R
R
4       h   + '       g   i     h ; ii ; i)z¦Create ``<base>.tar.gz`` of ``root_dir/base_dir`` in GNU tar format.

Writes to a sibling temp file and renames onto the archive path only after it is fully written.
z.tar.gzr   z	.archive_z.tar.gz.tmp)ÚdirÚprefixÚsuffixÚwbzw:gz)ÚfileobjÚmoder   )ÚarcnameN)ÚosÚpathÚdirnameÚtempfileÚmkstempÚfdopenÚtarfileÚopenÚ
GNU_FORMATÚaddr
   r   r   ÚBaseExceptionr   ÚOSErrorÚunlink)	r!   r"   r#   Úarchive_pathÚdest_dirÚfdÚtmp_pathÚfÚtfs	   &&&      r   Ú
make_targzr?      s  € ð
 �V˜7Ð#€LÜ�w‰w�‰˜|Ó,×3Ð3°€HÜ×#Ò#¨¸È]Ô[�L€BðÜ�YŠY�r˜4× Ô  AÜ—’ Q¨V¼G×<NÑ<N×OÕOÐSUØ�F‰F”3”t˜H“~¨Õ0Ó1¸8ˆFÔD÷ P÷ !ô 	�
Š
�8Ô*ð
 Ð÷ P×Oú÷ !× ûô ô Ü”g×ÕÜ�IŠI�hÔ÷ à÷ ÖàúðúsT   ÁD Á*0DÂ-C/	ÃDÃD Ã/C?Ã:DÄD	ÄD Ä"E+Ä7EÅ	E+ÅE'Å"	E+c               ó$   € V ^8„  d   QhRRRRRR/# )r   Úarchiver   Údestinationr   ÚNoner   )r   s   "r   r   r   2   s!   € ÷ 6ñ 6 ð 6°4ð 6¸Dñ 6r   c                óÌ  € \         P                  ! V R4      ;_uu_ 4       pVP                  4        EFW  pVP                  ! \	        VP
                  4      !  pVP                  4       '       d   VP                  RRR7       KR  VP                  4       '       g   \        RVP
                   24      hVP                  P                  RRR7       VP                  V4      pVf   \        RVP
                   24      hT;_uu_ 4        \        VR4      ;_uu_ 4       p\        P                  ! WV4       RRR4       RRR4       \        \        4      ;_uu_ 4        \         P"                  ! WCP$                  R,          4       RRR4       EKZ  	  RRR4       R#   + '       g   i     Ln; i  + '       g   i     Ly; i  + '       g   i     EKž  ; i  + '       g   i     R# ; i)	a  Extract ``archive`` into ``destination`` without path escapes or links.

Only directories and regular files are extracted; symlinks, hardlinks, and device nodes raise
rather than being silently skipped, so a tampered archive fails the import instead of landing a
partial tree.
úr:gzT©ÚparentsÚexist_okz!Unsupported archive member type: NzCannot read archive member: r(   iÿ  )r2   r3   Ú
getmembersÚjoinpathr   ÚnameÚisdirÚmkdirÚisfiler   ÚparentÚextractfileÚshutilÚcopyfileobjr   r7   r,   Úchmodr*   )rA   rB   r>   ÚmemberÚtargetÚ	extractedÚdsts   &&     r   Úsafe_extract_targzrX   2   s?  € ô 
�Š�g˜v×	&Ô	&¨"Ø—m‘m—oˆFØ ×)Ò)Ô+BÀ6Ç;Á;Ó+OÑPˆFØ�|‰|�~Š~Ø—‘ T°D�Ô9ÙØ—=‘=—?’?Ü Ð#DÀVÇ[Á[ÀMÐ!RÓSÐSØ�M‰M×Ñ¨°tÐÔ<ØŸ™ vÓ.ˆIØÒ Ü Ð#?ÀÇÁ¸}Ð!MÓNÐNß’œD ¨×.Ô.°#Ü×"Ò" 9Ô2÷ /—äœ'×"Õ"Ü—’˜§¡¨uÕ!4Ô5÷ #Ò"ñ &÷ 
'Ñ	&÷ /×.ú——úç"×"Ñ"ú÷ 
'×	&Ð	&ús[    A8GÂA,GÄF*ÄFÄ1F*Ä9GÅ(F=Æ GÆF'Æ"F*Æ*F:Æ5GÆ=GÇ
GÇG#	c               ó    € V ^8„  d   QhRRRR/# )r   rA   r   r   zset[str]r   )r   s   "r   r   r   K   s   € ÷ 
5ñ 
5˜tð 
5¨ñ 
5r   c           	     óV  € \         P                  ! V R4      ;_uu_ 4       pVP                  4        UUu0 uFI  p\        VP                  4      p\        V4      ^8”  g   VP                  4       '       g   K@  V^ ,          kKK  	  uppuuRRR4       # u uppi   + '       g   i     R# ; i)a  Return the archive's top-level directory names.

Transfer archives carry exactly one root directory, which names the thing being imported.
Inspecting before extraction lets the caller resolve the target name (and refuse a malformed
archive) without first mutating a live tree.
rE   N)r2   r3   rI   r   rK   ÚlenrL   )rA   r>   rT   r   s   &   r   Úarchive_root_dirsr\   K   sx   € ô 
�Š�g˜v×	&Ô	&¨"Ø')§}¡}¤ô 5¡˜VÜ5°f·k±kÓB�EÜ�u“: ”> V§\¡\§^ô ��a—�¡ò 5÷ 
'Ò	&ùó5÷ 
'×	&Ð	&ús"    B´=B
Á6B
ÂBÂBÂB(	c               ó$   € V ^8„  d   QhRRRRRR/# )r   Úsrcr   rW   r   Úintr   )r   s   "r   r   r   X   s!   € ÷ ñ ˜Dð  tð °ñ r   c                ó~  € V P                  4       '       g   ^ # ^ p\        V P                  R4      4       F„  pVP                  4       '       g   VP	                  4       '       g   K1  WP                  V 4      ,          pVP                  P                  RRR7       \        P                  ! W44       V^,          pK†  	  V# )zøCopy the regular files under ``src`` into ``dst``, skipping symlinks; return the count.

Used on the *export* side so a symlink planted in an attachments or logs tree can't pull an
arbitrary file into the archive. A missing ``src`` copies nothing.
Ú*TrF   )
Úis_dirÚsortedÚrglobÚ
is_symlinkÚis_fileÚrelative_torO   rM   rQ   Úcopyfile)r^   rW   ÚcopiedÚentryrU   s   &&   r   Úcopy_regular_filesrk   X   s�   € ð �:‰:�<Š<ÙØ€FÜ˜Ÿ	™	 #›Ö'ˆØ×Ñ×Ò U§]¡]§_¢_ÙØ×(Ñ(¨Ó-Õ-ˆØ�‰×Ñ D°4ÐÔ8Ü�Š˜Ô&Ø�!�Šñ (ð €Mr   )Ú__doc__Ú
__future__r   r,   rQ   r2   r/   Ú
contextlibr   Úpathlibr   r   r   r   r?   rX   r\   rk   r   r   r   Ú<module>rp      s9   ðÙ Qå "ã 	Û Û Û Ý ß 8Ñ 8õõ"õ(6õ2
5÷r   