From 2050d08cfd78c56e18f4b90968c3fc758efea78f Mon Sep 17 00:00:00 2001 From: caibo Date: Thu, 20 Aug 2015 17:40:29 +0800 Subject: [PATCH] rbd:remove the local file when rbd export-diff fail Signed-off-by: Bo Cai --- src/rbd.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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 -- 2.47.3