+
    „WÝj²  ã            
       ó\  € R t ^ RI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
HtHt ^ RIHt ^ RIHt ]P"                  ! ]4      t ! R R]4      tR R	 ltR
R/R R lltR R lt]R8X  d8   ]! ]P4                  ! ]! ]! ]P6                  ^,          4      4      4      4       R# R# )zëWAL-safe SQLite snapshots. Direct execution needs only the standard library.

Desktop invokes this file before stopping its backend, even when application
imports cannot load. Full and quick backups use the same SQLite copy operation.
N)Úsuppress)ÚdatetimeÚtimezoneÚUTC)ÚPath)ÚOptionalc                   ó   € ] tR t^tRtRtR# )Ú_SQLiteBackupTimeoutz=Raised when a SQLite snapshot remains busy past its deadline.© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__static_attributes__r
   ó    ÚLC:\Users\johnn\AppData\Local\hermes\hermes-agent\hermes_cli\backup_sqlite.pyr	   r	      s   † ÝGr   r	   c                óR   € V ^8„  d   QhR\         \        P                  ,          RR/# )é   ÚconnÚreturnN)r   Úsqlite3Ú
Connection)Úformats   "r   Ú__annotate__r      s%   € ÷ ñ œ¤'×"4Ñ"4Õ5ð ¸$ñ r   c                 óš   € V e3   \        \        4      ;_uu_ 4        V P                  4        R R R 4       R # R #   + '       g   i     R # ; i)N)r   Ú	ExceptionÚclose)r   s   &r   Ú_close_quietlyr      s3   € ØÒÜ”i× Õ Ø�J‰JŒL÷ !Ñ ñ ß × Ð ús	   œ9¹A
	Útimeout_secondsg      $@c                óH   € V ^8„  d   QhR\         R\         R\        R\        /# )r   ÚsrcÚdstr   r   )r   ÚfloatÚbool)r   s   "r   r   r      s(   € ÷ 1ñ 1”tð 1¤$ð 1¼Eð 1ÌTñ 1r   c               ól  aa	€ R;r4 \         P                  R8w  d˜   \         P                  \         P                  ,          p\	        \         R4      '       d   V\         P
                  ,          p\         P                  ! WR4      p \         P                  ! VR4       \         P                  ! V4       \        P                  ! V P                  4       P                  4        R2RRR7      p\        P                  ! \        V4      4      p\        P                  ! 4       \!        RS4      ,           o	R	 V	V3R
 llpVP#                  VRVRR7        \%        V4       \%        V4       R#   \         P                  ! T4       i ; i  \&         d‹   p\(        P+                  RY4       \%        T4       Rp\-        \.        4      ;_uu_ 4        TP1                  RR7       RRR4       M  + '       g   i     M; i Rp?\%        T4       \%        T4       R# Rp?ii ; i  \%        T4       \%        T4       i ; i)z¯Copy a SQLite database with the backup() API (WAL-safe consistent snapshot).

Fails closed when no consistent snapshot can be made: copying only the main file loses WAL data.
NÚntÚ
O_NOFOLLOWi€  z?mode=roTç        )ÚuriÚtimeoutc                ó@   € V ^8„  d   QhR\         R\         R\         RR/# )r   ÚstatusÚ
_remainingÚ_totalr   N)Úint)r   s   "r   r   Ú#_safe_copy_db.<locals>.__annotate__;   s/   € ÷ 	@ñ 	@¬3ð 	@¼Cð 	@Ìð 	@ÐQUñ 	@r   c                 óÔ   <€ \         P                  ! 4       pV \        P                  \        P                  39   d   VS8¼  d   \        R SR R24      hR# V\        RS4      ,           oR# )zdatabase remained locked for Úgz secondsr(   N)ÚtimeÚ	monotonicr   ÚSQLITE_BUSYÚSQLITE_LOCKEDr	   Úmax)r,   r-   r.   ÚnowÚbusy_deadliner   s   &&& €€r   Ú_check_backup_progressÚ-_safe_copy_db.<locals>._check_backup_progress;   sb   ø€ ä—.’.Ó"ˆCØœ'×-Ñ-¬w×/DÑ/DÐEÔEØ˜-Ô'Ü.Ð1NÈÐ_`ÐNaÐaiÐ/jÓkÐkñ (ð !$¤c¨#¨Ó&?Õ ?’r   é   gš™™™™™¹?)ÚpagesÚprogressÚsleepz"SQLite safe copy failed for %s: %s©Ú
missing_okF)ÚosÚnameÚO_WRONLYÚO_CREATÚhasattrr'   ÚopenÚfchmodr   r   ÚconnectÚresolveÚas_uriÚstrr3   r4   r7   Úbackupr   r   ÚloggerÚwarningr   ÚOSErrorÚunlink)
r!   r"   r   r   Úbackup_connÚ
open_flagsÚ	secure_fdr:   Úexcr9   s
   &&d      @r   Ú_safe_copy_dbrV      s•  ù€ ð
 Ð€Dð+ô �7‰7�dŒ?ÜŸ™¤r§z¡zÕ1ˆJÜ”r˜<×(Ò(ØœbŸm™mÕ+�
ÜŸš °Ó7ˆIð$Ü—	’	˜) UÔ+ä—’˜Ô#ô �Š #§+¡+£-×"6Ñ"6Ó"8Ð!9¸ÐBÈÐVYÔZˆÜ—o’o¤c¨#£hÓ/ˆÜŸšÓ(¬3¨s°OÓ+DÕDˆ÷	@ñ 	@ð 	�‰�K sÐ5KÐSVˆÔWØô 	�{Ô#Ü�tÖøô9 —’˜Õ#ûô$ ô Ü�‰Ð;¸SÔFä�{Ô#ØˆÜ”g×ÕØ�J‰J $ˆJÔ'÷ ××Ðúãä�{Ô#Ü�tÖûðûô 	�{Ô#Ü�tÕús[   ‡A>F ÂE( ÂB2F Å(F Æ F ÆHÆ:HÇG$Ç	HÇ$G4Ç/HÇ7H ÈHÈH ÈH3c                ó0   € V ^8„  d   QhR\         R\        /# )r   Úhomer   )r   Údict)r   s   "r   r   r   S   s   € ÷ 5ñ 5œTð 5¤dñ 5r   c                ó:  € V R,          pVP                  4       '       g   RRRR/# Rp\        P                  ! \        4      P	                  R4      pW V R\
        P                  ! 4        R	2,          p\        P                  ! VR
V R7      w  rV\
        P                  ! V4       \        V4      p \        W4      '       g   \        R4      h\        P                  ! \        V4      4      p VP!                  R4      P#                  4       p	V	R.8w  d   \        RV	 24      h VP                  4        VP%                  4       P&                  p
\
        P(                  ! Wt4       VP+                  RR7       \-        V P/                  V R24      RR7      R,           F  p VP+                  4        K  	  R\        V4      RV
/#   TP                  4        i ; i  TP+                  RR7       i ; i  \0         d"   p\2        P5                  RY¼4        Rp?Kz  Rp?ii ; i)zFPublish an emergency snapshot; do not prune recovery files on failure.zstate.dbÚpathNÚmessagez#state.db not found (fresh install?)zstate.db.pre-update-emergency-z%Y-%m-%dT%H-%M-%S-%fZÚ-z.bakz.partial)ÚprefixÚsuffixÚdirzCSQLite safe copy failed; previous emergency snapshots were retainedzPRAGMA quick_checkz(SQLite snapshot integrity check failed: Tr@   z*.bak)Úreverse:r   NNz)Could not prune emergency snapshot %s: %sÚbytes)Úok)Úexistsr   r8   r   ÚstrftimerB   ÚgetpidÚtempfileÚmkstempr   r   rV   ÚRuntimeErrorr   rI   rL   ÚexecuteÚfetchallÚstatÚst_sizeÚreplacerQ   ÚsortedÚglobrP   rN   rO   )rX   Úsourcer^   ÚstampÚdestinationÚfdrC   ÚstagedÚ
connectionÚresultÚsizeÚoldrU   s   &            r   Úpreflight_state_dbrz   S   sÌ  € à�JÕ€FØ�=‰=�?Š?Ø˜˜iÐ)NÐOÐOØ-€FÜ�LŠLœÓ×&Ñ&Ð'>Ó?€EØ˜8 E 7¨!¬B¯IªI«K¨=¸Ð=Õ=€KÜ×Ò v°jÀdÔK�H€BÜ‡H‚HˆR„LÜ�$‹Z€Fð'Ü˜V×,Ò,ÜÐdÓeÐeÜ—_’_¤S¨£[Ó1ˆ
ð	Ø×'Ñ'Ð(<Ó=×FÑFÓHˆFØ˜'˜Ô"Ü"Ð%MÈfÈXÐ#VÓWÐWð #ð ×ÑÔØ�{‰{‹}×$Ñ$ˆÜ
�
Š
�6Ô'à�‰ ˆÔ&Ü�d—i‘i 6 (¨%Ð 0Ó1¸4Ô@À×DÐDˆð	RØ�J‰JŽLñ Eð
 ”C˜Ó$ g¨tÐ4Ð4øð ×ÑÕûð 	�‰ ˆÕ&ûô ô 	RÜ�N‰NÐFÈ×QÒQûð	Rús=   Â1;G Ã-5G Ä#A G ÆG.ÇGÇG ÇG+Ç.HÇ9HÈHÚ__main__)r   ÚjsonÚloggingrB   r   Úsysrg   r3   Ú
contextlibr   r   r   r   Úpathlibr   Útypingr   Ú	getLoggerr   rN   ri   r	   r   rV   rz   ÚprintÚdumpsÚargvr
   r   r   Ú<module>r†      s™   ðñó
 Û Û 	Û Û 
Û Û Ý ß ,Ñ ,Ý Ý à	×	Ò	˜8Ó	$€ôH˜<ô Hõð1ÀD÷ 1õh5ðB ˆzÔÙ	ˆ$�*Š*Ñ'©¨S¯X©X°a­[Ó(9Ó:Ó
;Ö<ñ r   