Repository: spotify/luigi
File: luigi/contrib/azureblob.py (Python)

Code before:
        return self.connection.exists(container, blob)

    def remove(self, path, recursive=True, skip_trash=True):
        container, blob = self.splitfilepath(path)
        if not self.exists(path):
            return False
        lease_id = self.connection.acquire_blob_lease(container, blob)
        self.connection.delete_blob(container, blob, lease_id=lease_id)
        return True

    def mkdir(self, path, parents=True, raise_if_exists=False):
        container, blob = self.splitfilepath(path)
        if raise_if_exists and self.exists(path):
            raise FileAlreadyExists("The Azure blob path '{blob}' already exists under container '{container}'".format(
                blob=blob, contaniner=container))

    def isdir(self, path):
        """
        Azure Blob Storage has no concept of directories. It always returns False
        :param str path: Path of the Azure blob storage
        :return: False
        """
        return False

    def move(self, path, dest):
        return self.copy(path, dest) and self.remove(path)

    def copy(self, path, dest):
        source_container, source_blob = self.splitfilepath(path)
        dest_container, dest_blob = self.splitfilepath(dest)
        if source_container != dest_container:
            raise Exception(
                "Can't copy blob from '{source_container}' to '{dest_container}'. File can be moved within container".format(
                    source_container=source_container, dest_container=dest_container
                ))

        source_lease_id = self.connection.acquire_blob_lease(source_container, source_blob)
        destination_lease_id = self.connection.acquire_blob_lease(dest_container, dest_blob) if self.exists(dest) else None
        try:
            return self.connection.copy_blob(source_container, dest_blob, self.connection.make_blob_url(
                source_container, source_blob),
                destination_lease_id=destination_lease_id, source_lease_id=source_lease_id)
        finally:
            self.connection.release_blob_lease(source_container, source_blob, source_lease_id)
            if destination_lease_id is not None:
                self.connection.release_blob_lease(dest_container, dest_blob, destination_lease_id)

    def rename_dont_move(self, path, dest):
        self.move(path, dest)

    def splitfilepath(self, filepath):

Review comment (bug):
could `copy` succeed and `remove` fail? in that case, we have `path` in two locations

Code after:
        container, blob = self.splitfilepath(path)
        return self.connection.exists(container, blob)

    def remove(self, path, recursive=True, skip_trash=True):
        container, blob = self.splitfilepath(path)
        if not self.exists(path):
            return False
        lease_id = self.connection.acquire_blob_lease(container, blob)
        self.connection.delete_blob(container, blob, lease_id=lease_id)
        return True

    def mkdir(self, path, parents=True, raise_if_exists=False):
        container, blob = self.splitfilepath(path)
        if raise_if_exists and self.exists(path):
            raise FileAlreadyExists("The Azure blob path '{blob}' already exists under container '{container}'".format(
                blob=blob, contaniner=container))

    def isdir(self, path):
        """
        Azure Blob Storage has no concept of directories. It always returns False
        :param str path: Path of the Azure blob storage
        :return: False
        """
        return False

    def move(self, path, dest):
        try:
            return self.copy(path, dest) and self.remove(path)
        except IOError:
            self.remove(dest)
            return False

    def copy(self, path, dest):
        source_container, source_blob = self.splitfilepath(path)
        dest_container, dest_blob = self.splitfilepath(dest)
        if source_container != dest_container:
            raise Exception(
                "Can't copy blob from '{source_container}' to '{dest_container}'. File can be moved within container".format(
                    source_container=source_container, dest_container=dest_container
                ))

        source_lease_id = self.connection.acquire_blob_lease(source_container, source_blob)
        destination_lease_id = self.connection.acquire_blob_lease(dest_container, dest_blob) if self.exists(dest) else None
        try:
            return self.connection.copy_blob(source_container, dest_blob, self.connection.make_blob_url(
                source_container, source_blob),
                destination_lease_id=destination_lease_id, source_lease_id=source_lease_id)
        finally:
            self.connection.release_blob_lease(source_container, source_blob, source_lease_id)
            if destination_lease_id is not None:
                self.connection.release_blob_lease(dest_container, dest_blob, destination_lease_id)