]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
destroy the original container after making sure the snapshot exists (fixes #224)
authorS.Çağlar Onur <caglar@10ur.org>
Sun, 25 May 2014 02:19:06 +0000 (22:19 -0400)
committerStéphane Graber <stgraber@ubuntu.com>
Wed, 4 Jun 2014 14:55:11 +0000 (10:55 -0400)
Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
src/lxc/lxccontainer.c

index 255fde5760f47b5d32e75ce402210d38fb4af148..8296514ebe4e1a35715c2d71a65c8fa0b90b663c 100644 (file)
@@ -3090,13 +3090,7 @@ static bool lxcapi_snapshot_restore(struct lxc_container *c, const char *snapnam
 
        if (!newname)
                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);
        if (ret < 0 || ret >= MAXPATHLEN) {
                bdev_put(bdev);
@@ -3112,6 +3106,15 @@ static bool lxcapi_snapshot_restore(struct lxc_container *c, const char *snapnam
                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)
                flags = LXC_CLONE_SNAPSHOT | LXC_CLONE_MAYBE_SNAPSHOT;
        rest = lxcapi_clone(snap, newname, c->config_path, flags,