(f, dotlock=True)
Lock file f using lockf and dot locking.
Lock file f using lockf and dot locking.
Lock file f using lockf and dot locking .
def _lock_file(f, dotlock=True):
    """Lock file f using lockf and dot locking."""
    dotlock_done = False
    try:
        if fcntl:
            try:
                fcntl.lockf(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
            except OSError as e:
                if e.errno in (errno.EAGAIN, errno.EACCES, errno.EROFS):
                    raise ExternalClashError('lockf: lock unavailable: %s' %
                                             f.name)
                else:
                    raise
        if dotlock:
            try:
                pre_lock = _create_temporary(f.name + '.lock')
                pre_lock.close()
            except OSError as e:
                if e.errno in (errno.EACCES, errno.EROFS):
                    return  # Without write access, just skip dotlocking.
                else:
                    raise
            try:
                try:
                    os.link(pre_lock.name, f.name + '.lock')
                    dotlock_done = True
                except (AttributeError, PermissionError):
                    os.rename(pre_lock.name, f.name + '.lock')
                    dotlock_done = True
                else:
                    os.unlink(pre_lock.name)
            except FileExistsError:
                os.remove(pre_lock.name)
                raise ExternalClashError('dot lock unavailable: %s' %
                                         f.name)
    except:
        if fcntl:
            fcntl.lockf(f, fcntl.LOCK_UN)
        if dotlock_done:
            os.remove(f.name + '.lock')
        raise
def _lock_file ( f , dotlock = True ) : dotlock_done = False try : if fcntl : try : fcntl . lockf ( f , fcntl . LOCK_EX | fcntl . LOCK_NB ) except OSError as e : if e . errno in ( errno . EAGAIN , errno . EACCES , errno . EROFS ) : raise ExternalClashError ( 'lockf: lock unavailable: %s' % f . name ) else : raise if dotlock : try : pre_lock = _create_temporary ( f . name + '.lock' ) pre_lock . close ( ) except OSError as e : if e . errno in ( errno . EACCES , errno . EROFS ) : return # Without write access, just skip dotlocking. else : raise try : try : os . link ( pre_lock . name , f . name + '.lock' ) dotlock_done = True except ( AttributeError , PermissionError ) : os . rename ( pre_lock . name , f . name + '.lock' ) dotlock_done = True else : os . unlink ( pre_lock . name ) except FileExistsError : os . remove ( pre_lock . name ) raise ExternalClashError ( 'dot lock unavailable: %s' % f . name ) except : if fcntl : fcntl . lockf ( f , fcntl . LOCK_UN ) if dotlock_done : os . remove ( f . name + '.lock' ) raise