+
    lHàj)  ã                  óº   € R t ^ RIHt ^ RIt^ RIt^ RIHt ^ RIHt ^ RI	H
t
 . ROt]! ]R^ 4      tRR/R	 R
 lltRRRRRRRR/R R lltRRRRRRRR/R R lltR# )a†  Symlink-safe creation helpers for spill/cache files under ``~/.hermes``, where a plain
``open(path, "w")`` would follow a pre-planted symlink onto ``~/.bashrc`` etc. New files use
``O_CREAT | O_EXCL`` (fails on ANY existing path, even a dangling link); overwrites ``lstat`` +
``unlink`` first (removes the link, never its target) then create exclusively, so the pair
can't be raced. ``private=True`` (default) = ``0o700`` dirs / ``0o600`` files for spills that
may hold pre-redaction secrets; ``private=False`` keeps umask perms for cache dirs bind-mounted
into remote backends (``credential_files._CACHE_DIRS``). Disk failures raise ``OSError``.)ÚannotationsN)ÚPath)ÚIO)Úmake_user_dirÚ
O_NOFOLLOWÚprivateTc               ó$   € V ^8„  d   QhRRRRRR/# )é   Úpathr   r   ÚboolÚreturn© )Úformats   "Ú7/home/ubuntu/.hermes/hermes-agent/tools/spill_safety.pyÚ__annotate__r      s!   € ÷ ñ ˜4ð ¨Tð ¸Tñ ó    c               óh  € \        V 4      p \        Y'       d   RMRRRR7       \        P                  ! V 4      p\        P
                  ! VP                  4      '       g   \        RV  24      hV'       d=   \        P                  ! VP                  4      R8w  d   \        P                  ! V R4       V # )zÃCreate ``path`` (and parents) as a directory, refusing symlinks. ``private=True``
creates the leaf ``0o700`` and tightens an existing leaf. Raises ``OSError`` if the leaf
is not a real directory.iÀ  iÿ  T)ÚmodeÚparentsÚexist_okz)spill dir is not a directory (symlink?): )
r   r   ÚosÚlstatÚstatÚS_ISDIRÚst_modeÚOSErrorÚS_IMODEÚchmod)r
   r   Ústs   &$ r   Úensure_spill_dirr      s}   € ô �‹:€DÜ�$¦g™U°5À$ÐQUÕVÜ	�Š�$‹€BÜ�<Š<˜Ÿ
™
×#Ò#ÜÐAÀ$ÀÐHÓIÐIß”4—<’< §
¡
Ó+¨uÔ4Ü
�Š��uÔØ€Kr   Ú	overwriteFÚencodingzutf-8ÚerrorsÚstrictc               ó0   € V ^8„  d   QhRRRRRRRRRRR	R
/# )r	   r
   r   r   r   r    r!   Ústrr"   r   zIO[str]r   )r   s   "r   r   r   %   s9   € ÷ ñ ˜ð ¨4ð À4ð Ø ðØ47ðØGNñr   c               óZ  € \        V 4      p V'       db    \        P                  ! V 4      p\        P                  ! VP
                  4      '       d   \        RV  24      h\        P                  ! V 4       V'       d   RMRp\        P                  ! V \        P                  \        P                  ,          \        P                  ,          \        ,          V4      p \        P                  ! VRW4R7      #   \         d     LŽi ; i  \         d    \        P                   ! T4       h i ; i)u+  Open ``path`` for writing via exclusive create; never follows a link. ``overwrite=True``
first unlinks an existing path (``lstat``-checked, so only the link itself is removed and
directories are refused), then creates exclusively â€” the overwrite path cannot be
redirected through a symlink either.z#refusing to overwrite a directory: i€  i¶  Úw)r!   r"   )r   r   r   r   r   r   r   ÚunlinkÚFileNotFoundErrorÚopenÚO_WRONLYÚO_CREATÚO_EXCLÚ_O_NOFOLLOWÚfdopenÚ	ExceptionÚclose)r
   r   r    r!   r"   r   r   Úfds   &$$$$   r   Úopen_exclusiver3   %   sÕ   € ô �‹:€Dßð	Ü—’˜$“ˆBô �|Š|˜BŸJ™J×'Ò'ÜÐ CÀDÀ6ÐJÓKÐKÜ�IŠI�dŒOß‰5 €DÜ	�Š�”r—{‘{¤R§Z¡ZÕ/´"·)±)Õ;¼kÕIÈ4Ó	P€BðÜ�yŠy˜˜S¨8ÔCÐCøô !ô 	Ùð	ûô ô Ü
�Š�ŒØðús   •C6 ÃD Ã6DÄDÄ#D*c               ó4   € V ^8„  d   QhRRRRRRRRRRR	RR
R/# )r	   r
   r   Útextr%   r   r   r    r!   r"   r   ÚNoner   )r   s   "r   r   r   >   sA   € ÷ ñ ˜tð ¨3ð ¸Dð ÐTXð Ø#&ðØ:=ðØMQñr   c               óŽ   € \        WW4VR7      ;_uu_ 4       pVP                  V4       RRR4       R#   + '       g   i     R# ; i)z?``Path.write_text`` equivalent that refuses to follow symlinks.)r   r    r!   r"   N)r3   Úwrite)r
   r5   r   r    r!   r"   Úfhs   &&$$$$ r   Úwrite_text_exclusiver:   >   s;   € ô 
˜¸Ø%÷
'õ 
'Ø*,Ø
�‰�Œ÷
'÷ 
'÷ 
'ò 
'ús	   —3³A	)r   r3   r:   )Ú__doc__Ú
__future__r   r   r   Úpathlibr   Útypingr   Úhermes_dir_aclr   Ú__all__Úgetattrr.   r   r3   r:   r   r   r   Ú<module>rB      sŒ   ðñ]õ #ã 	Û Ý Ý Ý (â
H€ñ �b˜,¨Ó*€ð°D÷ ð°$ð È%ð Ø#*ðØ:B÷ð2À4ð Ð[`ð Ø)0ðØ@H÷ñ r   