
    ɯei_                    z    d dl mZ d dlZd dlZd dlmZ d dlmZ d dlmZ dZ	dZ
dZ G d	 d
e      Z G d d      Zy)    )annotationsN)stat_result)Path)sleep   g?   c                      e Zd Zy)FileLockErrorN)__name__
__module____qualname__     _/var/www/html/glpi_dashboard/venv/lib/python3.12/site-packages/snowflake/connector/file_lock.pyr
   r
      s    r   r
   c                       e Zd ZddZd Zd Zy)FileLockc                \    || _         d| _        t        j                  t              | _        y NF)pathlockedlogging	getLoggerr   logger)selfr   s     r   __init__zFileLock.__init__   s"    	''1r   c                b   d }	 | j                   j                         }|r^|j
                  t        j                         t        z
  k  r6| j                  j                  d       	 | j                   j                          t        }t        t              D ]N  }| j                  j                  d| d| d       |dz  }	 | j                   j                  d	
       d| _         n | j                  st	        dt         d      y # t        $ r Y t        $ r }t	        d| j                    d|      d }~ww xY w# t        $ r Y t        $ r }t	        d| j                    d|      d }~ww xY w# t         $ r t#        |       Y t        $ r }t	        d| j                    d|      d }~ww xY w)NzFailed to stat lock file z
 due to e=zRemoving stale file lockz!Failed to remove stale lock file z"Trying to acquire file lock after z seconds in attempt number .   i  )modeTzFailed to acquire lock file z#Failed to acquire file lock, after z
 attempts.)r   statFileNotFoundErrorOSErrorr
   st_ctimetimeSTALE_LOCK_AGE_SECONDSr   debugrmdirINITIAL_BACKOFF_SECONDSrangeMAX_RETRIESmkdirr   FileExistsErrorr   )r   statinfoebackoff_secondsattempts        r   	__enter__zFileLock.__enter__   s   '+	Uyy~~'H ))DIIK:P,PPKK89		! 2[) 	GKK4_4EE`ah`iijk .1O
		U+"	" {{5k]*M  E ! 	 	U";DII;kqd STT	U %  #7		{+1$O  # o& #2499+[aTJ sY   D $D: >#E0	D7D7D22D7:	E-E-E((E-0F.F.F))F.c                t    	 | j                   j                          d| _        y # t        $ r
 Y d| _        y w xY wr   )r   r'   r!   r   )r   exc_typeexc_valexc_tbcs       r   __exit__zFileLock.__exit__C   s9    	IIOO  ! 		s   $ 	77N)r   r   returnNone)r   r   r   r   r1   r6   r   r   r   r   r      s    2
)Vr   r   )
__future__r   r   r$   osr   pathlibr   r   r*   r(   r%   	Exceptionr
   r   r   r   r   <module>r=      s>    "       	I 	6 6r   