U
    UV\
                     @   sP   d dl mZ d dlZd dlZddlmZmZmZmZm	Z	m
Z
 G dd deZdS )    )absolute_importN   )LockBase
LockFailed	NotLocked	NotMyLockLockTimeoutAlreadyLockedc                   @   s:   e Zd ZdZdddZdd Zdd Zd	d
 Zdd ZdS )LinkLockFilezLock access to a file using atomic property of link(2).

    >>> lock = LinkLockFile('somefile')
    >>> lock = LinkLockFile('somefile', threaded=False)
    Nc                 C   s   zt | jd  W n" tk
r6   td| j Y nX |d k	rD|n| j}t }|d k	rj|dkrj||7 }zt| j| j	 W n t
k
r   t| jj}|dkrY d S |d k	rt |krt| j |dkrtd| j ntd| j t|d k	r
|d pd Y qjX d S qjd S )	Nwbzfailed to create %sr      z&Timeout waiting to acquire lock for %sz%s is already locked
   g?)openunique_namecloseIOErrorr   timeouttimeoslink	lock_fileOSErrorstatst_nlinkunlinkr   pathr	   sleep)selfr   Zend_timeZnlinks r   4lib/python3.8/site-packages/lockfile/linklockfile.pyacquire   s2    $zLinkLockFile.acquirec                 C   sP   |   std| j ntj| js4td| j t| j t| j d S )Nz%s is not lockedz%s is locked, but not by me)		is_lockedr   r   r   existsr   r   r   r   r   r   r   r   release7   s    zLinkLockFile.releasec                 C   s   t j| jS N)r   r   r"   r   r#   r   r   r   r!   ?   s    zLinkLockFile.is_lockedc                 C   s(   |   o&tj| jo&t| jjdkS )Nr   )r!   r   r   r"   r   r   r   r#   r   r   r   i_am_lockingB   s
    zLinkLockFile.i_am_lockingc                 C   s   t j| jrt | j d S r%   )r   r   r"   r   r   r#   r   r   r   
break_lockG   s    zLinkLockFile.break_lock)N)	__name__
__module____qualname____doc__r    r$   r!   r&   r'   r   r   r   r   r
   
   s   
&r
   )Z
__future__r   r   r    r   r   r   r   r   r	   r
   r   r   r   r   <module>   s    