def test_deleted_subvolumes(self): subvol = os.path.join(self.mountpoint, 'subvol') btrfsutil.create_subvolume(subvol + '1') btrfsutil.delete_subvolume(subvol + '1') for arg in self.path_or_fd(self.mountpoint): with self.subTest(type=type(arg)): self.assertEqual(btrfsutil.deleted_subvolumes(arg), [256])
def delete_snapshot(self, snapshot: Subvolume) -> None: logger = self._logger filesystem_path = snapshot.filesystem_path logical_path = snapshot.logical_path try: filesystem_path_str = str(filesystem_path) is_subvolume = filesystem_path.exists() and btrfsutil.is_subvolume( filesystem_path_str) if is_subvolume: root_dir_str = str(constants.ROOT_DIR) num_id = snapshot.num_id deleted_subvolumes = checked_cast( list[int], btrfsutil.deleted_subvolumes(root_dir_str)) if num_id not in deleted_subvolumes: logger.info(f"Deleting the '{logical_path}' snapshot.") btrfsutil.delete_subvolume(filesystem_path_str) else: logger.warning( f"The '{logical_path}' snapshot has already " "been deleted but not yet cleaned up.") else: logger.warning( f"The '{filesystem_path}' directory is not a subvolume.") except btrfsutil.BtrfsUtilError as e: logger.exception("btrfsutil call failed!") raise SubvolumeError( f"Could not delete the '{logical_path}' snapshot!") from e