Skip to content

Commit

Permalink
Implement option to delete snapshot
Browse files Browse the repository at this point in the history
Requested in [gh##52]
  • Loading branch information
laenion committed Jul 5, 2022
1 parent 163e15d commit 550026a
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/Bindings/CBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,18 @@ void tukit_free_sm_list(tukit_sm_list list) {
delete result;
}

int tukit_sm_deletesnap(const char* id) {
try {
std::unique_ptr<TransactionalUpdate::SnapshotManager> snapshotMgr = TransactionalUpdate::SnapshotFactory::get();
snapshotMgr->deleteSnap(id);
return 0;
} catch (const std::exception &e) {
fprintf(stderr, "ERROR: %s\n", e.what());
errmsg = e.what();
return -1;
}
}

int tukit_reboot(const char* method) {
try {
auto rebootmgr = Reboot{method};
Expand Down
1 change: 1 addition & 0 deletions lib/Bindings/libtukit.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ typedef void* tukit_sm_list;
tukit_sm_list tukit_sm_get_list(size_t* len, const char* columns);
const char* tukit_sm_get_list_value(tukit_sm_list list, size_t row, size_t columns);
void tukit_free_sm_list(tukit_sm_list list);
int tukit_sm_deletesnap(const char* id);
int tukit_reboot(const char* method);

#ifdef __cplusplus
Expand Down
4 changes: 4 additions & 0 deletions lib/Snapshot/Snapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ std::string Snapper::getDefault() {
return match[1].str();
}

void Snapper::deleteSnap(std::string id) {
callSnapper("delete " + id);
}

bool Snapper::isInProgress() {
std::string desc = callSnapper("--csvout list --columns number,userdata");
std::smatch match;
Expand Down
1 change: 1 addition & 0 deletions lib/Snapshot/Snapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Snapper: public SnapshotManager, public Snapshot {
std::deque<std::map<std::string, std::string>> getList(std::string columns) override;
std::string getCurrent() override;
std::string getDefault() override;
void deleteSnap(std::string id) override;
private:
std::string callSnapper(std::string);
inline static bool snapperNoDbus;
Expand Down
1 change: 1 addition & 0 deletions lib/SnapshotManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class SnapshotManager
virtual std::deque<std::map<std::string, std::string>> getList(std::string columns) = 0;
virtual std::string getCurrent() = 0;
virtual std::string getDefault() = 0;
virtual void deleteSnap(std::string id) = 0;
};

class SnapshotFactory {
Expand Down
2 changes: 2 additions & 0 deletions lib/Transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class Transaction {
/**
* @brief Execute the given application in the new snapshot
* @param argv
* @param (optional) output Variable to store the command's output to
* @return application's return code
*
* Execute any given command within the new snapshot. The application's output will be
Expand All @@ -92,6 +93,7 @@ class Transaction {
/**
* @brief Replace '{}' in argv with mount directory and execute command
* @param argv
* @param (optional) output Variable to store the command's output to
* @return application's return code
*
* Replace any standalone occurrence of '{}' in argv with the snapshot's mount directory
Expand Down

0 comments on commit 550026a

Please sign in to comment.