def delete(self, name, version, _lock=True):
        link_path = self._link_path(name)
        if _lock:
            file_lock = _exclusive_lock(self._lock_path('links', name))
        else:
            file_lock = _no_lock()
        with file_lock:
            logger.debug('Acquired or inherited lock for link %s.', name)
            if not _path_exists(link_path):
                raise FiletrackerFileNotFoundError
            if _file_version(link_path) > version:
                logger.info(
                    'Tried to delete newer version of %s (%d < %d), ignoring.',
                    name, version, _file_version(link_path))
                return False
            digest = self._digest_for_link(name)
            with _exclusive_lock(self._lock_path('blobs', digest)):
                logger.debug('Acquired lock for blob %s.', digest)
                should_delete_blob = False
                with self._db_transaction() as txn:
                    logger.debug('Started DB transaction (deleting link).')
                    digest_bytes = digest.encode()
                    link_count = self.db.get(digest_bytes, txn=txn)
                    if link_count is None:
                        raise RuntimeError("File exists but has no key in db")
                    link_count = int(link_count)
                    if link_count == 1:
                        logger.debug('Deleting last link to blob %s.', digest)
                        self.db.delete(digest_bytes, txn=txn)
                        self.db.delete(
                                '{}:logical_size'.format(digest).encode(),
                                txn=txn)
                        should_delete_blob = True
                    else:
                        new_count = str(link_count - 1).encode()
                        self.db.put(digest_bytes, new_count, txn=txn)
                    logger.debug('Committing DB transaction (deleting link).')
                logger.debug('Committed DB transaction (deleting link).')
                os.unlink(link_path)
                logger.debug('Deleted link %s.', name)
                if should_delete_blob:
                    os.unlink(self._blob_path(digest))
            logger.debug('Released lock for blob %s.', digest)
        logger.debug('Released (or gave back) lock for link %s.', name)
        return True