B
    @)H[¥
  ã               @   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 )ÚLinkLockFilez�Lock access to a file using atomic property of link(2).

    >>> lock = LinkLockFile('somefile')
    >>> lock = LinkLockFile('somefile', threaded=False)
    Nc             C   s"  y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 }x²yt | j| j	¡ W n” t
k
�r   t | j¡j}|dkr¬d S |d k	ròt ¡ |kròt | j¡ |dkrätd| j ƒ‚ntd| j ƒ‚t |d k	�r
|d �pd¡ Y qlX d S qlW d 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   Úend_timeÚnlinks© r    úbC:\Users\HIRONO~1\AppData\Local\Temp\pip-install-qz7kpjmn\pip\pip\_vendor\lockfile\linklockfile.pyÚacquire   s0    
$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 )N)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
   )Ú
__future__r   r   r   Ú r   r   r   r   r   r	   r
   r    r    r    r!   Ú<module>   s    