diff --git a/src/platform/backends/qemu/qemu_snapshot.cpp b/src/platform/backends/qemu/qemu_snapshot.cpp index 916b0c64a6..aa23f0f26f 100644 --- a/src/platform/backends/qemu/qemu_snapshot.cpp +++ b/src/platform/backends/qemu/qemu_snapshot.cpp @@ -33,9 +33,6 @@ namespace mpp = mp::platform; namespace { -const auto snapshot_template = QStringLiteral("@%1"); /* avoid colliding with suspension snapshots; prefix with a char - that can't be part of the name, to avoid confusion */ - std::unique_ptr make_capture_spec(const QString& tag, const mp::Path& image_path) { return std::make_unique(QStringList{"snapshot", "-c", tag, image_path}, @@ -80,7 +77,7 @@ mp::QemuSnapshot::QemuSnapshot(const QJsonObject& json, QemuVirtualMachine& vm, void mp::QemuSnapshot::capture_impl() { - auto tag = derive_tag(); + auto tag = derive_id(); // Avoid creating more than one snapshot with the same tag (creation would succeed, but we'd then be unable to // identify the snapshot by tag) @@ -93,7 +90,7 @@ void mp::QemuSnapshot::capture_impl() void mp::QemuSnapshot::erase_impl() { - checked_exec_qemu_img(make_delete_spec(derive_tag(), image_path)); + checked_exec_qemu_img(make_delete_spec(derive_id(), image_path)); } void mp::QemuSnapshot::apply_impl() @@ -105,11 +102,6 @@ void mp::QemuSnapshot::apply_impl() desc.mem_size = get_mem_size(); desc.disk_space = get_disk_space(); - checked_exec_qemu_img(make_restore_spec(derive_tag(), image_path)); + checked_exec_qemu_img(make_restore_spec(derive_id(), image_path)); rollback.dismiss(); } - -QString mp::QemuSnapshot::derive_tag() const -{ - return snapshot_template.arg(get_name().c_str()); -} diff --git a/src/platform/backends/qemu/qemu_snapshot.h b/src/platform/backends/qemu/qemu_snapshot.h index 2424690193..81480a1eb1 100644 --- a/src/platform/backends/qemu/qemu_snapshot.h +++ b/src/platform/backends/qemu/qemu_snapshot.h @@ -41,9 +41,6 @@ class QemuSnapshot : public BaseSnapshot void erase_impl() override; void apply_impl() override; -private: - QString derive_tag() const; - private: VirtualMachineDescription& desc; const Path& image_path; diff --git a/src/platform/backends/shared/base_snapshot.cpp b/src/platform/backends/shared/base_snapshot.cpp index 939c2aebb0..f09467069d 100644 --- a/src/platform/backends/shared/base_snapshot.cpp +++ b/src/platform/backends/shared/base_snapshot.cpp @@ -29,6 +29,9 @@ namespace mp = multipass; namespace { +const auto snapshot_template = QStringLiteral("@%1"); /* avoid colliding with suspension snapshots; prefix with a char + that can't be part of the name, to avoid confusion */ + std::unordered_map load_mounts(const QJsonArray& json) { std::unordered_map mounts; @@ -197,3 +200,8 @@ QJsonObject multipass::BaseSnapshot::serialize() const return ret; } + +QString multipass::BaseSnapshot::derive_id() const +{ + return snapshot_template.arg(get_name().c_str()); +} diff --git a/src/platform/backends/shared/base_snapshot.h b/src/platform/backends/shared/base_snapshot.h index 411c952c95..126e19183b 100644 --- a/src/platform/backends/shared/base_snapshot.h +++ b/src/platform/backends/shared/base_snapshot.h @@ -69,6 +69,8 @@ class BaseSnapshot : public Snapshot virtual void erase_impl() = 0; virtual void apply_impl() = 0; + QString derive_id() const; + private: struct InnerJsonTag {