From: caibo Date: Thu, 20 Aug 2015 09:40:29 +0000 (+0800) Subject: rbd:remove the local file when rbd export-diff fail X-Git-Tag: v9.1.0~327^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F5587%2Fhead;p=ceph.git rbd:remove the local file when rbd export-diff fail Signed-off-by: Bo Cai --- diff --git a/src/rbd.cc b/src/rbd.cc index f8eedb02ff35..72f81df7e631 100755 --- a/src/rbd.cc +++ b/src/rbd.cc @@ -1357,6 +1357,13 @@ static int do_export_diff(librbd::Image& image, const char *fromsnapname, if (fd < 0) return -errno; + BOOST_SCOPE_EXIT(&r, &fd, &path) { + close(fd); + if (r < 0 && fd != 1) { + remove(path); + } + } BOOST_SCOPE_EXIT_END + { // header bufferlist bl; @@ -1384,7 +1391,6 @@ static int do_export_diff(librbd::Image& image, const char *fromsnapname, r = bl.write_fd(fd); if (r < 0) { - close(fd); return r; } } @@ -1410,7 +1416,6 @@ static int do_export_diff(librbd::Image& image, const char *fromsnapname, } out: - close(fd); if (r < 0) ec.pc.fail(); else