Commit 70f3eb4e by S.Çağlar Onur Committed by Stéphane Graber

destroy the original container after making sure the snapshot exists (fixes #224)

parent 35d0ebf1
...@@ -3090,13 +3090,7 @@ static bool lxcapi_snapshot_restore(struct lxc_container *c, const char *snapnam ...@@ -3090,13 +3090,7 @@ static bool lxcapi_snapshot_restore(struct lxc_container *c, const char *snapnam
if (!newname) if (!newname)
newname = c->name; newname = c->name;
if (strcmp(c->name, newname) == 0) {
if (!lxcapi_destroy(c)) {
ERROR("Could not destroy existing container %s", newname);
bdev_put(bdev);
return false;
}
}
ret = snprintf(clonelxcpath, MAXPATHLEN, "%ssnaps/%s", c->config_path, c->name); ret = snprintf(clonelxcpath, MAXPATHLEN, "%ssnaps/%s", c->config_path, c->name);
if (ret < 0 || ret >= MAXPATHLEN) { if (ret < 0 || ret >= MAXPATHLEN) {
bdev_put(bdev); bdev_put(bdev);
...@@ -3112,6 +3106,15 @@ static bool lxcapi_snapshot_restore(struct lxc_container *c, const char *snapnam ...@@ -3112,6 +3106,15 @@ static bool lxcapi_snapshot_restore(struct lxc_container *c, const char *snapnam
return false; return false;
} }
if (strcmp(c->name, newname) == 0) {
if (!lxcapi_destroy(c)) {
ERROR("Could not destroy existing container %s", newname);
lxc_container_put(snap);
bdev_put(bdev);
return false;
}
}
if (strcmp(bdev->type, "dir") != 0 && strcmp(bdev->type, "loop") != 0) if (strcmp(bdev->type, "dir") != 0 && strcmp(bdev->type, "loop") != 0)
flags = LXC_CLONE_SNAPSHOT | LXC_CLONE_MAYBE_SNAPSHOT; flags = LXC_CLONE_SNAPSHOT | LXC_CLONE_MAYBE_SNAPSHOT;
rest = lxcapi_clone(snap, newname, c->config_path, flags, rest = lxcapi_clone(snap, newname, c->config_path, flags,
......
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