From 203067a2742ad2cbb986369b216b1f1ecfb96458 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 29 Sep 2015 13:06:08 +0200 Subject: Automatically cleanup package archive, directory on failure --- bpkg/pkg-unpack.cxx | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'bpkg/pkg-unpack.cxx') diff --git a/bpkg/pkg-unpack.cxx b/bpkg/pkg-unpack.cxx index ba98b0b..84dd5ae 100644 --- a/bpkg/pkg-unpack.cxx +++ b/bpkg/pkg-unpack.cxx @@ -115,6 +115,11 @@ namespace bpkg if (exists (d)) fail << "package directory " << d << " already exists"; + // What should we do if tar or something after it fails? Cleaning + // up the package directory sounds like the right thing to do. + // + auto_rm_r arm (d); + const char* args[] { "tar", "-C", c.string ().c_str (), // -C/--directory -- change to directory. @@ -125,17 +130,6 @@ namespace bpkg if (verb >= 2) print_process (args); - // What should we do if tar or something after it fails? Cleaning - // up the package directory sounds like the right thing to do. - // - auto dg ( - make_exception_guard ( - [&d]() - { - if (exists (d)) - rm_r (d); - })); - try { process pr (args); @@ -165,6 +159,8 @@ namespace bpkg db.update (p); t.commit (); + arm.cancel (); + return p; } -- cgit v1.1