
^V\
                 @   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
 Gd d   d e  Z d S)    )absolute_importN   )LockBase
LockFailed	NotLocked	NotMyLockLockTimeoutAlreadyLockedc               @   sU   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   sz  y t  |  j d  j   Wn% t k
 rA t d |  j   Yn X| d  k	 rT | n |  j } t j   } | d  k	 r | d k r | | 7} n  x y t j |  j |  j	  Wn t
 k
 rmt j |  j  j } | d k r d  S| d  k	 rFt j   | k rFt j |  j  | d k r0t d |  j   qFt d |  j   n  t j | d  k	 rb| d ped  Yq Xd  Sq Wd  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    @/tmp/pip-build-9m6vxulb/pip/pip/_vendor/lockfile/linklockfile.pyacquire   s0    (zLinkLockFile.acquirec             C   sq   |  j    s" t d |  j   n+ t j j |  j  sM t d |  j   n  t j |  j  t j |  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 |  j  S)N)r   r   r$   r   )r   r    r    r!   r#   ?   s    zLinkLockFile.is_lockedc             C   s:   |  j    o9 t j j |  j  o9 t j |  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 |  j  r( t  j |  j  n  d  S)N)r   r   r$   r   r   )r   r    r    r!   
break_lockG   s    zLinkLockFile.break_lock)	__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   .