o
    RDi_                     @  sn   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
 d
eZG dd dZdS )    )annotationsN)stat_result)Path)sleep   g?   c                   @  s   e Zd ZdS )FileLockErrorN)__name__
__module____qualname__ r   r   V/var/www/Datamplify/venv/lib/python3.10/site-packages/snowflake/connector/file_lock.pyr      s    r   c                   @  s&   e Zd ZdddZdd Zd	d
 ZdS )FileLockpathr   returnNonec                 C  s   || _ d| _tt| _d S NF)r   lockedlogging	getLoggerr	   logger)selfr   r   r   r   __init__   s   zFileLock.__init__c                 C  sp  d }z| j  }W n ty   Y n ty( } ztd| j  d|d }~ww |ra|jt t k ra| j	d z| j 
  W n tyJ   Y n ty` } ztd| j  d|d }~ww t}ttD ]C}| j	d| d| d |d }z| j jd	d
 d| _W  n# ty   t| Y qg ty } ztd| j  d|d }~ww | jstdt dd S )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attemptr   r   r   	__enter__   sZ   
zFileLock.__enter__c                 C  s,   z| j   W n	 ty   Y nw d| _d S r   )r   r#   r   r   )r   exc_typeexc_valexc_tbcr   r   r   __exit__C   s   
zFileLock.__exit__N)r   r   r   r   )r	   r
   r   r   r-   r1   r   r   r   r   r      s    
+r   )
__future__r   r   r    osr   pathlibr   r   r&   r$   r!   	Exceptionr   r   r   r   r   r   <module>   s    