Skip to content

Commit

Permalink
[snapshot] move creation timestamp to base class
Browse files Browse the repository at this point in the history
  • Loading branch information
sharder996 committed Jun 23, 2023
1 parent 5bf3d89 commit cc38527
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/platform/backends/qemu/qemu_snapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void checked_exec_qemu_img(std::unique_ptr<mp::QemuImgProcessSpec> spec)

mp::QemuSnapshot::QemuSnapshot(const std::string& name, const std::string& comment,
std::shared_ptr<const Snapshot> parent, const VMSpecs& specs, const QString& image_path)
: BaseSnapshot(name, comment, QDateTime::currentDateTimeUtc(), std::move(parent), specs), image_path{image_path}
: BaseSnapshot(name, comment, std::move(parent), specs), image_path{image_path}
{
}

Expand Down
21 changes: 14 additions & 7 deletions src/platform/backends/shared/base_snapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ std::shared_ptr<const mp::Snapshot> find_parent(const QJsonObject& json, const m
}
} // namespace

mp::BaseSnapshot::BaseSnapshot(const std::string& name, const std::string& comment,
const QDateTime& creation_timestamp, // NOLINT(modernize-pass-by-value)
mp::BaseSnapshot::BaseSnapshot(const std::string& name, const std::string& comment, const QDateTime& creation_timestamp,
std::shared_ptr<const Snapshot> parent, int num_cores, MemorySize mem_size,
MemorySize disk_space, VirtualMachine::State state,
std::unordered_map<std::string, VMMount> mounts, QJsonObject metadata)
Expand All @@ -104,10 +103,18 @@ mp::BaseSnapshot::BaseSnapshot(const std::string& name, const std::string& comme
throw std::runtime_error{fmt::format("Invalid disk size for snapshot: {}", disk_bytes)};
}

mp::BaseSnapshot::BaseSnapshot(const std::string& name, const std::string& comment, const QDateTime& creation_timestamp,
mp::BaseSnapshot::BaseSnapshot(const std::string& name, const std::string& comment,
std::shared_ptr<const Snapshot> parent, const VMSpecs& specs)
: BaseSnapshot{name, comment, creation_timestamp, std::move(parent), specs.num_cores,
specs.mem_size, specs.disk_space, specs.state, specs.mounts, specs.metadata}
: BaseSnapshot{name,
comment,
QDateTime::currentDateTimeUtc(),
std::move(parent),
specs.num_cores,
specs.mem_size,
specs.disk_space,
specs.state,
specs.mounts,
specs.metadata}
{
}

Expand All @@ -120,7 +127,7 @@ mp::BaseSnapshot::BaseSnapshot(InnerJsonTag, const QJsonObject& json, const Virt
: BaseSnapshot{json["name"].toString().toStdString(), // name
json["comment"].toString().toStdString(), // comment
QDateTime::fromString(json["creation_timestamp"].toString(),
"yyyy-MM-ddTHH:mm:ss.zzzZ"), // creation_timestamp
Qt::ISODate), // creation_timestamp
find_parent(json, vm), // parent
json["num_cores"].toInt(), // num_cores
MemorySize{json["mem_size"].toString().toStdString()}, // mem_size
Expand All @@ -138,7 +145,7 @@ QJsonObject multipass::BaseSnapshot::serialize() const

snapshot.insert("name", QString::fromStdString(name));
snapshot.insert("comment", QString::fromStdString(comment));
snapshot.insert("creation_timestamp", creation_timestamp.toString("yyyy-MM-ddTHH:mm:ss.zzzZ"));
snapshot.insert("creation_timestamp", creation_timestamp.toString(Qt::ISODate));
snapshot.insert("num_cores", num_cores);
snapshot.insert("mem_size", QString::number(mem_size.in_bytes()));
snapshot.insert("disk_space", QString::number(disk_space.in_bytes()));
Expand Down
4 changes: 2 additions & 2 deletions src/platform/backends/shared/base_snapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ struct VMSpecs;
class BaseSnapshot : public Snapshot
{
public:
BaseSnapshot(const std::string& name, const std::string& comment, const QDateTime& creation_timestamp,
std::shared_ptr<const Snapshot> parent, const VMSpecs& specs);
BaseSnapshot(const std::string& name, const std::string& comment, std::shared_ptr<const Snapshot> parent,
const VMSpecs& specs);
BaseSnapshot(const QJsonObject& json, const VirtualMachine& vm);

std::string get_name() const override;
Expand Down

0 comments on commit cc38527

Please sign in to comment.