Skip to content

Commit

Permalink
[api] additional function to reset to the last snapshot position
Browse files Browse the repository at this point in the history
Also QML plugin is switched to use this function instead of resetMaster(),
otherwise if previous backup was interrupted, intermediate commits will be
included into next backup

Signed-off-by: Denis Zalevskiy <denis.zalevskiy@jolla.com>
  • Loading branch information
Denis Zalevskiy committed Sep 17, 2015
1 parent 24adc29 commit 8e11134
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
4 changes: 3 additions & 1 deletion include/vault/vault.hpp
Expand Up @@ -94,9 +94,10 @@ class Vault

Lock lock() const;

void resetLastSnapshot();

std::tuple<QString, bool, QString> backupUnit(const QString &, const QString &);
QString tagSnapshot(const QString &message);
void resetMaster();

std::tuple<QString, bool, QString> restoreUnit
(const QString &, const QString &, const QString &);
Expand All @@ -106,6 +107,7 @@ class Vault
bool backupUnit(const QString &home, const QString &unit, const ProgressCallback &callback);
bool restoreUnit(const QString &home, const QString &unit, const ProgressCallback &callback);
void checkout(const QString &);
void resetMaster();

void setup(const QVariantMap *config);
QString absolutePath(QString const &) const;
Expand Down
4 changes: 2 additions & 2 deletions qml/Vault/vault.cpp
Expand Up @@ -66,8 +66,8 @@ class Worker : public QObject

Q_INVOKABLE void reset()
{
debug::debug("Reset storage");
m_vault->resetMaster();
debug::debug("Reset storage master to the last snapshot");
m_vault->resetLastSnapshot();
emit done(Vault::Maintenance, {{"operation", "reset"}});
}

Expand Down
21 changes: 20 additions & 1 deletion src/vault.cpp
Expand Up @@ -430,7 +430,7 @@ Vault::Result Vault::backup(const QString &home, const QStringList &units, const
qDebug() << "Progress" << name << status;
};

resetMaster();
resetLastSnapshot();
Gittin::Commit head = Gittin::Branch(&m_vcs, "master").head();

QStringList usedUnits = units;
Expand Down Expand Up @@ -535,6 +535,25 @@ void Vault::resetMaster()
m_vcs.checkout("master", CheckoutOptions::Force);
}

/**
* Reset master branch to the last snapshot commit
*
* This action should be done before doing backup to avoid inclusion
* of any traces/remnants of previous backup tryouts
*/
void Vault::resetLastSnapshot()
{
auto l = lock();
resetMaster();

QString lastSnapshot = "anchor";
auto snaps = snapshots();
if (!snaps.isEmpty())
lastSnapshot = snaps.back().tag().name();

m_vcs.reset(ResetOptions::Hard, lastSnapshot);
}

Vault::Result Vault::restore(const QString &snapshot, const QString &home, const QStringList &units, const ProgressCallback &callback)
{
auto l = lock();
Expand Down

0 comments on commit 8e11134

Please sign in to comment.