Commit 89f29b2b authored by deztructor's avatar deztructor

Merge branch 'staging' into 'master'

Add ability to export any snapshot as file tree



See merge request !1
parents debcfffc a74ee5b2
import QtQuick 2.0
import NemoMobile.Vault 1.1
QtObject {
property Vault vault: Vault {
onDone: vaultOperationDone(operation, data)
onProgress: vaultOperationProgress(operation, data)
onError: vaultOperationError(operation, error)
onData: vaultData(id, context)
}
// event handlers
function vaultOperationDone(operation, data) {
console.log("vault operation", operation, "done")
var action
switch (operation) {
case Vault.Connect:
break
case Vault.Maintenance:
break
case Vault.Backup:
break
case Vault.Restore:
break
case Vault.RemoveSnapshot:
break
case Vault.ExportSnapshot:
console.log("snapshot exporting is done"
, data.rc, data.snapshot, data.dst
, data.stdout, data.stderr)
break
case Vault.ExportImportPrepare:
break
case Vault.ExportImportExecute:
break
default:
break
}
}
function vaultData(operation, context) {
switch (operation) {
case Vault.SnapshotUnits:
break
case Vault.Snapshots:
break
case Vault.Units:
break
default:
break
}
}
function vaultOperationProgress(operation, data) {
switch (operation) {
case Vault.Backup:
break
case Vault.Restore:
break
case Vault.ExportImportExecute:
break
default:
break
}
}
function vaultOperationError(operation, error) {
console.log("vault operation", operation, "error")
switch (operation) {
case Vault.Connect:
break
case Vault.Backup:
break
case Vault.Restore:
break
case Vault.RemoveSnapshot:
break
case Vault.ExportImportPrepare:
break
case Vault.ExportImportExecute:
break
case Vault.ExportSnapshot:
console.log("error exporting snapshot"
, error.rc, error.snapshot, error.dst
, error.stdout, error.stderr)
default:
break
}
}
}
......@@ -102,6 +102,7 @@ public:
std::tuple<QString, bool, QString> restoreUnit
(const QString &, const QString &, const QString &);
std::tuple<int, QString, QString> exportSnapshot(QString const &, QString const&);
private:
bool setState(const QString &state);
bool backupUnit(const QString &home, const QString &unit, const ProgressCallback &callback);
......
......@@ -224,6 +224,19 @@ public:
}
}
Q_INVOKABLE void exportSnapshot(const QString &snapshot, const QString &dstDir)
{
auto res = m_vault->exportSnapshot(snapshot, dstDir);
int rc = std::get<0>(res);
auto data = map({{"snapshot", snapshot}, {"dst", dstDir}
, {"rc", std::get<0>(res)}, {"stdout", std::get<1>(res)}
, {"stderr", std::get<2>(res)}});
if (!rc)
emit done(Vault::ExportSnapshot, data);
else
emit error(Vault::ExportSnapshot, data);
}
signals:
void progress(Vault::Operation op, const QVariantMap &map);
void error(Vault::Operation op, const QVariantMap &error);
......@@ -419,4 +432,11 @@ Q_INVOKABLE void Vault::restoreUnit(const QString &snapshot, const QString &unit
, Q_ARG(QString, unit));
}
void Vault::exportSnapshot(const QString &snapshot, const QString &dstDir)
{
QMetaObject::invokeMethod(m_worker, "exportSnapshot"
, Q_ARG(QString, snapshot)
, Q_ARG(QString, dstDir));
}
#include "vault.moc"
......@@ -29,7 +29,8 @@ public:
ExportImportPrepare,
ExportImportExecute,
Data,
Maintenance
Maintenance,
ExportSnapshot
}
Q_ENUMS(Operation);
......@@ -67,6 +68,7 @@ public:
Q_INVOKABLE void tagSnapshot(const QString &message);
Q_INVOKABLE void restoreUnit(const QString &, const QString &);
Q_INVOKABLE void exportSnapshot(const QString &, const QString &);
signals:
void rootChanged();
......
......@@ -35,8 +35,6 @@ QVariantMap options_info
, {"required", true}, {"has_param", true}})}
, {"home-dir", map({{"short", "H"}, {"long", "home-dir"}
, {"required", true}, {"has_param", true}})}
, {"name", map({{"short", "n"}, {"long", "name"}
, {"required", true}, {"has_param", true}})}
, {"action", map({{"short", "a"}, {"long", "action"}
, {"required", true}, {"has_param", true}})}};
......
......@@ -797,6 +797,18 @@ bool Vault::restoreUnit(const QString &home, const QString &unit, const Progress
return true;
}
std::tuple<int, QString, QString>
Vault::exportSnapshot(const QString &snapshot, const QString &dstDir)
{
debug::debug("Export snapshot", snapshot, "to", dstDir);
auto l = lock();
auto snapshotName = snapshot;
if (snapshotName[0] != '>')
snapshotName = QString(">") + snapshot;
return executeIn(root(), "git-vault-export", snapshotName, dstDir);
}
/**
* \note thread-unsafe
*/
......@@ -842,7 +854,6 @@ void Unit::execScript(const QString &action)
error::raise({{"msg", "Should be executable"}, {"script", script}});
}
QStringList args = { "--action", action,
"--name", m_unit,
"--dir", QDir(m_data).absolutePath(),
"--bin-dir", QDir(m_blobs).absolutePath(),
"--home-dir", m_home };
......
configure_file(vault-gc.service.in vault-gc.service @ONLY)
install(
PROGRAMS git-vault-gc gc-default git-vault-snapshot-units
PROGRAMS git-vault-gc gc-default git-vault-snapshot-units git-vault-export
DESTINATION ${TOOLS_DIR}
)
......
#!/bin/bash
trace () {
echo "`basename $0`: ${@:1}" 1>&2;
}
error() {
trace $@
exit 1
}
[ $# -eq 2 ] || error "Usage: $0 snapshot dst_dir"
SNAP=$1
DST=$2
if [ "${SNAP:0:1}" != ">" ]; then
SNAP=">$SNAP"
fi
git rev-parse --show-toplevel || error "Not a git dir $(pwd)"
git rev-parse "$SNAP" >/dev/null || error "There is no snapshot $SNAP"
[ -d $DST ] || error "There is no destination dir $DST"
# only $DST itself is expected
COUNT=$(find $DST -maxdepth 1 -not -name '.' | wc -l)
if [ "x$COUNT" != "x1" ]; then
error "Dst dir $DST should be empty, found $COUNT entries"
fi
trace "Export $SNAP to the $DST"
GIT_DIR=$(pwd)
(git archive --format=tar "$SNAP" | tar -C $DST -xf -) || \
error "Export of $SNAP to the $DST is failed"
find $DST -type l | grep '/blobs/' | while read -r LINK
do
NAME=$(readlink $LINK)
# match minimal relative blob ref (path inside the tree is unit/blobs/link)
if [[ $NAME =~ \.\./\.\./\.git/blobs/ ]]; then
FNAME=$(basename $NAME)
DNAME="$GIT_DIR/.git/blobs/$(basename $(dirname $NAME))"
[ -d $DNAME ] || error "There is no blob dir $DNAME for $LINK"
FNAME="$DNAME/$FNAME"
[ -f $FNAME ] || error "There is no blob file $FNAME for $LINK"
unlink $LINK || error "Can't unlink $LINK"
cp $FNAME $LINK || error "Can't copy $FNAME to $LINK"
fi
done
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment