def _close_volume()

in export/securedrop_export/disk/cli.py [0:0]


    def _close_volume(self, mv: MountedVolume) -> Volume:
        """
        Unmount and close volume.
        """
        logger.debug(f"Unmounting drive {mv.unlocked_name} from {mv.mountpoint}")
        try:
            subprocess.check_call(
                [
                    "udisksctl",
                    "unmount",
                    "--block-device",
                    quote(mv.unlocked_name),
                ],
                # Redirect stderr/stdout to avoid broken pipe when subprocess terminates,
                # which results in qrexec attempting to parse error lines written to stderr
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )

        except subprocess.CalledProcessError as ex:
            logger.error(ex)
            logger.error("Error unmounting device")

            raise ExportException(sdstatus=Status.ERROR_UNMOUNT_VOLUME_BUSY) from ex

        logger.debug(f"Closing drive {mv.device_name}")
        try:
            subprocess.check_call(
                [
                    "udisksctl",
                    "lock",
                    "--block-device",
                    quote(mv.device_name),
                ],
                # Redirect stderr/stdout to avoid broken pipe when subprocess terminates
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
            )

        except subprocess.CalledProcessError as ex:
            logger.error("Error closing device")
            raise ExportException(sdstatus=Status.ERROR_EXPORT_CLEANUP) from ex

        return Volume(
            device_name=f"{_DEV_PREFIX}{mv.device_name}",
            encryption=mv.encryption,
        )