+
    .pÐjå/  ã                  ó*  € R t ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RI	H
t
 ^ RIHt ]P                  ! ]4      tRt^tRt^t ! R R]
4      tR R	 ltR
 R ltR R ltR R ltR R lt]3R R lltR R ltR R ltRR R lltR R ltR# )aÆ  Scratch-dir retention: idle detection plus the reaping an idle tree needs before it goes.

Deleting an idle ``cache/scratch/<entry>`` is not enough on its own: a lane's e2e run leaves
headless browsers whose cwd was inside the tree (they survived for days with a ``(deleted)``
cwd), and a repo whose linked worktree lived in the tree keeps a dangling registration until
someone runs ``git worktree prune``. Both are reaped here, right before ``rmtree``.
)ÚannotationsN)ÚRotatingFileHandler)ÚPathg      @c                  ó2   a € ] tR t^!tRtR V 3R lltRtV ;t# )Ú_PruneLogHandlera,  Rollover that tolerates a concurrent prune of the same home rotating first: its rename
of ``scratch-prune.log`` can land between this handler's existence check and its own
rename. The rotation is then already done, so the record goes to the new file instead of
being dropped with a FileNotFoundError.c               ó   € V ^8„  d   QhRR/# )é   ÚreturnÚNone© )Úformats   "Ú'/opt/hermes/hermes_constants_scratch.pyÚ__annotate__Ú_PruneLogHandler.__annotate__'   s   € ÷ !ñ !˜Dñ !ó    c                	ó¢   <€ \         P                  ! \        4      ;_uu_ 4        \        SV `  4        R R R 4       R #   + '       g   i     R # ; i©N)Ú
contextlibÚsuppressÚFileNotFoundErrorÚsuperÚ
doRollover)ÚselfÚ	__class__s   &€r   r   Ú_PruneLogHandler.doRollover'   s/   ø€ Ü× Ò Ô!2×3Õ3Ü‰GÑÔ ÷ 4×3×3Ò3ús	   ¤=½A	r   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   Ú__static_attributes__Ú__classcell__)r   s   @r   r   r   !   s   ø† ñ/÷
!ö !r   r   c               ó    € V ^8„  d   QhRRRR/# )r   Úlog_fileúPath | Noner	   úlogging.Loggerr   )r   s   "r   r   r   ,   s   € ÷ ñ ˜kð ¨nñ r   c           	     óî  € V f   \         #  V P                  P                  RRR7       \
        P                  ! \         P                  \
        P                  4      p\         Tn        \        T \        \        RRRR7      pTP                  \
        P                  ! R4      4       TP                  T4       T#   \         d2   p\         P	                  RT P                  T4       \         u Rp?# Rp?ii ; i)	a  Logger for one prune's records, with its own RotatingFileHandler on *log_file*, so a
prune that runs at boot (before ``setup_logging()``) still leaves them on disk. Records also
propagate through this module's logger to whatever logging is set up.

One unregistered logger per prune, closed when it ends: no process holds the file open
between prunes (an open handle blocks rollover on Windows), and prunes of two homes never
share a handler. Without a *log_file* (test-runner temp roots) this module's logger is used.
NT)ÚparentsÚexist_okz#scratch prune: cannot create %s: %súutf-8Úbackslashreplace)ÚmaxBytesÚbackupCountÚencodingÚerrorsÚdelayz%(asctime)s %(message)s)ÚloggerÚparentÚmkdirÚOSErrorÚwarningÚloggingÚLoggerÚnameÚINFOr   Ú_PRUNE_LOG_MAX_BYTESÚ_PRUNE_LOG_BACKUPSÚsetFormatterÚ	FormatterÚ
addHandler)r#   ÚexcÚauditÚhandlers   &   r   Ú_open_prune_logrA   ,   sÄ   € ð ÒÜˆðØ�‰×Ñ d°TÐÔ:ô �NŠNœ6Ÿ;™;¬¯©Ó5€EÜ€E„Lô ØÔ/Ô=OÐZaØ!¨ô€Gð ×Ñœ×*Ò*Ð+DÓEÔFØ	×Ñ�WÔØ€Løô ô Ü�‰Ð<¸h¿o¹oÈsÔSÜ�ûðús   ŒB8 Â8C4Ã&C/Ã)C4Ã/C4c               ó    € V ^8„  d   QhRRRR/# )r   Úpathr   r	   Úintr   )r   s   "r   r   r   I   s   € ÷ ñ �dð ˜sñ r   c                ó’  €  \         P                  ! V 4      P                  pT P	                  4       '       d#   T P                  4       '       g   \        T 4      .M. pT'       dš    \         P                  ! TP                  4       4      ;_uu_ 4       pT F[  p YP                  RR7      P                  ,          pTP	                  RR7      '       g   K@  TP                  TP                  4       K]  	  RRR4       K¡  T#   \         d     ^ # i ; i  \         d     K‹  i ; i  + '       g   i     KØ  ; i  \         d     Ké  i ; i)zGApparent size of *path* and everything under it, symlinks not followed.F©Úfollow_symlinksN)ÚosÚlstatÚst_sizer3   Úis_dirÚ
is_symlinkÚstrÚscandirÚpopÚstatÚappendrC   )rC   ÚtotalÚstackÚitÚchilds   &    r   Ú_tree_bytesrV   I   sþ   € ðÜ—’˜“×&Ñ&ˆð  Ÿ;™;Ÿ=š=°·±×1BÒ1BŒS�‹Y‰KÈ€Eß
ð
	Ü—’˜EŸI™I›K×(Ô(¨BÛ�Eð!Ø§¡¸E Ó!B×!JÑ!JÕJ˜ð —|‘|°E�|×:Ô:ØŸ™ U§Z¡ZÖ0ñ  ÷ )Ñ(ð €Løô ô Úðûô #ô !Ú ð!ú÷	 )×(Ð(ûô ô 	Úð	úsk   ‚ C? Á%,D7 ÂD#Â"DÂ:D#ÃD#Ã3D7 Ã?DÄDÄD 	ÄD#ÄD 	Ä D#Ä#D4	Ä.D7 Ä4D7 Ä7EÅEc               ó$   € V ^8„  d   QhRRRRRR/# )r   rC   r   ÚcutoffÚfloatr	   Úboolr   )r   s   "r   r   r   _   s!   € ÷ ñ  ð ¨eð ¸ñ r   c                óÊ  €  \         P                  ! V 4      P                  V8¼  d   R# V P                  4       '       d   V P	                  4       '       d   R#  \        T 4      .pT'       d¥    \         P                  ! TP                  4       4      ;_uu_ 4       pT Ff  p TP                  RR7      P                  T8¼  d    RRR4       R#  TP                  RR7      '       g   KK  TP                  TP                  4       Kh  	  RRR4       K¬  R#   \
         d     R# i ; i  \
         d      RRR4       R# i ; i  + '       g   i     Kì  ; i  \
         d     R# i ; i)a›  True when *path* or anything beneath it has an mtime at or after *cutoff*.

Stops at the first recent entry, so a live tree costs one hit and only a truly idle
tree pays for the full walk (once, right before it is deleted). Symlinks are never
followed: a link into the repo would make the target's activity keep the entry alive.
An unreadable entry is kept: an incomplete scan cannot establish that it is idle.
TFrF   N)rH   rI   Úst_mtimerK   rL   r3   rM   rN   rO   rP   rQ   rC   )rC   rX   rS   rT   rU   s   &&   r   Úsubtree_touched_sincer]   _   s"  € ðÜ�8Š8�D‹>×"Ñ" fÔ,ÙØ�{‰{�}Š} §¡× 1Ò 1Ùð !2ô �‹YˆK€Eß
ð	Ü—’˜EŸI™I›K×(Ô(¨BÛ�Eð$Ø Ÿ:™:°e˜:Ó<×EÑEÈÔOØ#'÷	 )Ñ(ð Pð —|‘|°E�|×:Ô:ØŸ™ U§Z¡ZÖ0ñ  ÷ )Ñ(ñ øô! ô Úðûô #ô $Ù#÷ )Ñ(ð
$ú÷ )×(Ð(ûô ô 	Úð	ús‡   ‚%D ©D ¿D Á-,E ÂD?Â !D$ÃD?ÃE ÃD?Ã'D?ÄE ÄD!Ä D!Ä$D<	Ä/D?Ä1E Ä;D<	Ä<D?Ä?E	Å
E ÅE ÅE"Å!E"c               ó$   € V ^8„  d   QhRRRRRR/# )r   rC   rM   Úrootr	   rZ   r   )r   s   "r   r   r      s&   € ÷ Iñ I�ð I˜Cð I Dñ Ir   c                ó    € W8H  ;'       gD    V P                  VP                  \        P                  4      \        P                  ,           4      # r   )Ú
startswithÚrstriprH   Úsep)rC   r_   s   &&r   Ú_underrd      s1   € Ø‰<×HÐH˜4Ÿ?™?¨4¯;©;´r·v±vÓ+>ÄÇÁÕ+GÓHÐHr   c               ó   € V ^8„  d   QhRR/# )r   r	   zset[int]r   )r   s   "r   r   r   ƒ   s   € ÷ ñ �hñ r   c                 ó  € ^ RI p \        4       p V P                  4       pVe?   VP                  V9  d.   VP	                  VP                  4       VP                  4       pKB  V#   T P                  \        3 d     T# i ; i)zOThis process and its ancestors: never reap the shell that is running the prune.N)ÚpsutilÚsetÚProcessÚpidÚaddr1   ÚErrorr3   )rg   ÚpidsÚprocs      r   Ú_own_lineagero   ƒ   sr   € ãä“U€DðØ�~‰~ÓˆØÒ 4§8¡8°4Ô#7Ø�H‰H�T—X‘XÔØ—;‘;“=ŠDð €Køð �L‰Lœ'Ð"ô ØØ€Kðús   �AA$ Á$A?Á>A?c               ó(   € V ^8„  d   QhRRRRRRRR/# )	r   Úscratch_rootr   Údoomedz
list[Path]r?   r%   r	   rD   r   )r   s   "r   r   r   ’   s)   € ÷ 4ñ 4¨4ð 4¸ð 4ÈNð 4Ðhkñ 4r   c                ón  a€ ^ RI p\        P                  P                  \	        V 4      4      pV Uu. uF+  p\        P                  P                  \	        V4      4      NK-  	  pp\        4       p\        \        R4      '       d   \        P                  ! 4       MRp. p	VP                  R.4       EF  p
V
P                  V9   d   K   Ve"   V
P                  4       P                  V8w  d   K=  V
P                  4       pT'       g   KW  TP                  R4      pT'       d   TR\!        R4      )  MTo\#        ST4      '       g   K•  T'       gi   \        P                  P%                  S4      '       dD   \&        ;QJ d    T3R lT 4       F  '       g   K   RM	  RM! T3R lT 4       4      '       g   EK  T	P)                  T
S34       EK  	  V	'       g   ^ # V	 FE  w  p
o V
P+                  4       pV
P-                  4        TP/                  RT
P                  TS4       KG  	  TP1                  V	 U
Uu. uF  w  r®V
NK	  	  upp
\2        R	7      w  rïV FQ  p
 V
P5                  4       VP6                  8X  d   K%  V
P9                  4        TP/                  R
T
P                  4       KS  	  \:        P/                  R\!        V	4      4       \!        V	4      # u upi   TP                  \        3 d     EK@  i ; i  TP                  \        3 d     EK6  i ; iu upp
i   TP                  \        3 d     Kâ  i ; i)aŒ  TERM (then KILL) same-user processes whose cwd is inside an entry about to be
pruned, or is a path under *scratch_root* that no longer exists. Returns the count.

Only the cwd is consulted: a process merely holding a file open inside scratch (an
editor, a log tail) is not ours to kill, but one *living* in a directory we are
about to delete, or in one already gone, has nothing left to run for.
NÚgetuidrj   z
 (deleted)c              3  ó<   <"  € T F  p\        SV4      x € K  	  R # 5ir   )rd   )Ú.0ÚtÚcwd_paths   & €r   Ú	<genexpr>Ú+reap_processes_rooted_in.<locals>.<genexpr>°   s   øé € Ð9_ÑW^ÐRS¼&ÀÈ1×:MÐ:MÓW^ùs   ƒTFz.scratch prune: sent TERM pid=%d name=%r cwd=%r)Útimeoutz:scratch prune: sent KILL pid=%d (still running after TERM)z=scratch prune: reaped %d process(es) rooted in pruned entries)rg   rH   rC   ÚrealpathrM   ro   Úhasattrrt   Úprocess_iterrj   ÚuidsÚrealÚcwdrl   r3   ÚendswithÚlenrd   ÚexistsÚanyrQ   r7   Ú	terminateÚinfoÚ
wait_procsÚ_REAP_GRACE_SECONDSÚstatusÚSTATUS_ZOMBIEÚkillr0   )rq   rr   r?   rg   r_   ÚpÚtargetsÚskipÚuidÚvictimsrn   r�   Údeletedr7   Ú_Úaliverx   s   &&&             @r   Úreap_processes_rooted_inr•   ’   sƒ  ø€ ó ä�7‰7×ÑœC Ó-Ó.€DÙ17Ó8±¨AŒr�w‰w×Ñ¤ A£Ö'±€GÐ8Ü‹>€DÜ ¤ X×.Ò.Œ"�)Š)Œ+°D€CØ02€GØ×#Ñ# U G×,ˆØ�8‰8�tÔÙð	ØŠ 4§9¡9£;×#3Ñ#3°sÔ#:ÙØ—(‘(“*ˆC÷ ÙØ—,‘,˜|Ó,ˆß07�3Ð+œ#˜lÓ+Ð+Ñ,¸SˆÜ�h ×%Ò%Ùßœ"Ÿ'™'Ÿ.™.¨×2Ò2·c³cÔ9_ÑW^Ó9_·c·c²cÔ9_ÑW^Ó9_×6_Õ6_Ø�N‰N˜D (Ð+×,ñ! -÷" ÙÛ!‰ˆˆhð	Ø—9‘9“;ˆDØ�N‰NÔð 	�
‰
ÐCÀTÇXÁXÈtÐU]Ö^ñ "ð × Ñ ±gÔ!>±g©7¨4£$±gÒ!>ÔH[Ð Ó\�H€AÛˆð	à�{‰{‹} × 4Ñ 4Ô4ÙØ�I‰IŒKð 	�
‰
ÐOÐQU×QYÑQYÖZñ ô ‡K�KÐOÔQTÐU\ÓQ]Ô^Üˆw‹<ÐùòS 9øð —‘œgÐ&ô 	Ûð	ûð  —‘œgÐ&ô 	Ûð	üó "?øð —‘œgÐ&ô 	Úð	úsM   ²1KÃ#KÃ-KÇ  K4È2L
ÉLÉ6LËK1Ë0K1Ë4LÌLÌL4Ì3L4c               ó    € V ^8„  d   QhRRRR/# )r   Úentryr   r	   úset[str]r   )r   s   "r   r   r   É   s   € ÷ ñ  $ð ¨8ñ r   c           	     óN  € \        4       p\        V 4      ^ 3.pV'       EdÉ   VP                  4       w  r4 \        P                  ! V4      ;_uu_ 4       pV EF„  pVP
                  R8X  Ed   VP                  RR7      '       dö    \        VP                  4      P                  RRR7      P                  4       pTP                  R4      '       d§   \        T\        R4      R P                  4       4      pTP                  P
                  R	8X  dd   TP                  P                  P
                  R8X  d<   TP                  \        TP                  P                  P                  4      4       EK  EK  EK   EK#  VP!                  RR7      '       g   EK>  V\"        8  g   EKL  VP
                  R
9  g   EK`  VP%                  VP                  V^,           34       EK‡  	  RRR4       EKÑ  V#   \         d     EK¥  i ; i  + '       g   i     EKø  ; i  \         d     EK
  i ; i)ziRepos whose linked worktrees live inside *entry* (``.git`` FILES, ``gitdir: <repo>/.git/worktrees/<n>``).z.gitFrF   r)   Úreplace)r-   r.   zgitdir:NÚ	worktrees)Únode_modulesz.venvÚvenv)rh   rM   rO   rH   rN   r7   Úis_filer   rC   Ú	read_textÚstripr3   ra   rƒ   r1   rk   rK   Ú_GIT_FILE_MAX_DEPTHrQ   )	r—   ÚreposrS   ÚcurrentÚdepthrT   rU   ÚlineÚgitdirs	   &        r   Ú_linked_worktree_reposr§   É   s   € ä“e€EÜ�%‹j˜!ˆ_Ð€Eß
ˆ%ØŸ™›‰ˆð	Ü—’˜G×$Ô$¨Ü�EØ—z‘z VÕ+°·±Èe°×0TÒ0Tð%Ü#'¨¯
©
Ó#3×#=Ñ#=ÀwÐW`Ð#=Ó#a×#gÑ#gÓ#i˜Dð  Ÿ?™?¨9×5Ò5Ü%)¨$¬s°9«~¨Ð*?×*EÑ*EÓ*GÓ%H˜Fà%Ÿ}™}×1Ñ1°[Ô@ÀVÇ]Á]×EYÑEY×E^ÑE^ÐbhÔEhØ %§	¡	¬#¨f¯m©m×.BÑ.B×.IÑ.IÓ*J× Kò FiÒ@ò 6ð
 Ÿ™°e˜×<Õ<ÀÔI\×A\Ø %§
¡
Ð2S× SØŸ™ e§j¡j°%¸!µ)Ð%<×=ñ  ÷ %Ò$ð" €Løô  'ô %Û$ð%ú÷ %×$Ñ$ûô ô 	Ûð	úsl   µH Á0G?Â4G,Â9G?ÃB>G?ÆG?Æ"G?Æ6)G?ÇH Ç,G<	Ç7G?Ç;G<	Ç<G?Ç?H	È
H ÈH ÈH$È#H$c               ó    € V ^8„  d   QhRRRR/# )r   r¢   r˜   r	   r
   r   )r   s   "r   r   r   ä   s   € ÷ Kñ K ð K¨dñ Kr   c                óZ  € \        V 4       F\  p\        P                  P                  V4      '       g   K*   \        P
                  ! RRVRR.\        P                  RRRR^RR	7       K^  	  R#   \        \        P                  3 d"   p\        P                  R
Y4        Rp?K™  Rp?ii ; i)zT``git worktree prune`` in each repo: drops registrations whose tree we just deleted.Úgitz-CÚworktreeÚpruneTr)   rš   F)ÚstdinÚcapture_outputÚtextr-   r.   r{   Úcheckz#git worktree prune in %s failed: %sN)ÚsortedrH   rC   ÚisdirÚ
subprocessÚrunÚDEVNULLr3   ÚSubprocessErrorr0   Údebug)r¢   Úrepor>   s   &  r   Úrelease_git_worktreesr¹   ä   s�   € ä�u–ˆÜ�w‰w�}‰}˜T×"Ò"Ùð	KÜ�NŠNØ˜˜d J°Ð8Ü ×(Ñ(¸ÀDÐSZÐclØ %÷ó	 øô œ×3Ñ3Ð4ô 	KÜ�L‰LÐ>À×JÒJûð	Kús   ·1A.Á.B*Â	B%Â%B*c          
     ó,   € V ^8„  d   QhRRRRRRRRR	R
/# )r   r_   r   Úmax_idle_hoursrY   Ú
skip_namesúfrozenset[str]r#   r$   r	   rD   r   )r   s   "r   r   r   ó   s4   € ÷  ñ  Ø
ð Ø %ð Ø3Að ØMXð àñ r   c                óô   € \        V4      p \        WW$4      V\        Jd%   VP                   F  pVP	                  4        K  	  # #   T\        Jd%   TP                   F  pTP	                  4        K  	  i i ; i)a
  Delete top-level entries of *root* with no write anywhere in their subtree for
*max_idle_hours*, reaping processes and worktree registrations rooted in them first.
Each removal and each signalled process is recorded in *log_file*. Returns the count
actually removed.)rA   Ú_prune_idle_entriesr0   ÚhandlersÚclose)r_   r»   r¼   r#   r?   r@   s   &&&&  r   Úprune_idle_entriesrÂ   ó   sf   € ô ˜HÓ%€Eð Ü" 4¸ÓKàœÓØ Ÿ>œ>�Ø—‘–ò *ð øˆ5œÓØ Ÿ>œ>�Ø—‘–ò *ð ús   �A Á0A7c          
     ó,   € V ^8„  d   QhRRRRRRRRR	R
/# )r   r_   r   r»   rY   r¼   r½   r?   r%   r	   rD   r   )r   s   "r   r   r     s4   € ÷ %ñ %Ø
ð%Ø %ð%Ø3Að%ØJXð%àñ%r   c                ód  € \         P                   ! 4       VR ,          ,
          p V P                  4        Uu. uF  qUP                  V9  g   K  VNK  	  ppT Uu. uF  p\	        YT4      '       d   K  TNK  	  pp \        YT4       T'       g   ^ # \        4       p	^ p
T Fô  p\        T4      p TP                  4       '       dB   TP                  4       '       g,   T	\        T4      ,          p	\        P                  ! TRR7       MTP!                  4         \$        P(                  P+                  T4      '       d)   TP#                  R\$        P&                  ! T4      4       KÄ  TP#                  R\$        P&                  ! T4      T4       T
^,          p
Kö  	  \-        T	4       T
# u upi   \         d     ^ # i ; iu upi   \         d$   p\        P                  RTRR7        Rp?ELbRp?ii ; i  \         d4   pTP#                  R\$        P&                  ! T4      T4        Rp?EK‹  Rp?ii ; i)	i  z'scratch prune: process reap skipped: %sT)Úexc_infoN)Úignore_errorsz&scratch prune: could not remove %r: %sz(scratch prune: could not fully remove %rz$scratch prune: removed %r (%d bytes))ÚtimeÚiterdirr7   r3   r]   r•   Ú	Exceptionr0   r·   rh   rV   rK   rL   r§   ÚshutilÚrmtreeÚunlinkr‡   rH   ÚfspathrC   Úlexistsr¹   )r_   r»   r¼   r?   rX   ÚeÚentriesrr   r>   r¢   Úremovedr—   Úsizes   &&&&         r   r¿   r¿     s¶  € ô �YŠY‹[˜>¨DÕ0Õ0€FðØ"Ÿl™lœnÓI™n˜·±¸jÑ0H—1�1™nˆÐIñ !ÓI™�AÔ(=¸a×(H�aˆa™€FÐIðTÜ  ¨uÔ5÷ ÙÜ“e€EØ€GÛˆÜ˜5Ó!ˆð	Ø�|‰|�~Š~ e×&6Ñ&6×&8Ò&8ØÔ/°Ó6Õ6�Ü—’˜e°4Ö8à—‘•ô
 �7‰7�?‰?˜5×!Ò!Ø�J‰JÐAÄ2Ç9Â9ÈUÓCSÔTÙØ�
‰
Ð9¼2¿9º9ÀUÓ;KÈTÔRØ�1�Šñ! ô" ˜%Ô Ø€NùòA JøÜô ÚðüâIøô
 ô TÜ�‰Ð>ÀÈdˆ×SÒSûðTûô ô 	Ø�J‰JÐ?ÄÇÂÈ5ÓAQÐSVÔWÞûð	úsp   ¥F) ·F$ÁF$ÁF) ÁF;Á2F;Á;G  Â.+G1Ã*G1ÄG1Æ$F) Æ)F8Æ7F8Ç G.ÇG)Ç)G.Ç1H/Ç<'H*È*H/i  P r   )r   Ú
__future__r   r   r5   rH   rÊ   r³   rÇ   Úlogging.handlersr   Úpathlibr   Ú	getLoggerr   r0   r‰   r¡   r9   r:   r   rA   rV   r]   rd   ro   r•   r§   r¹   rÂ   r¿   r   r   r   Ú<module>r×      s�   ðñõ #ã Û Û 	Û Û Û Ý 0Ý à	×	Ò	˜8Ó	$€ð Ð àÐ ð 'Ð ØÐ ô
!Ð*ô !õõ:õ,õ@Iõð ^d÷ 4õnõ6K÷ ÷ %r   