aboutsummaryrefslogtreecommitdiff
path: root/bpkg/pkg-unpack.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-09-29 13:06:08 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-09-29 13:06:08 +0200
commit203067a2742ad2cbb986369b216b1f1ecfb96458 (patch)
treeb3b755ca08aba82a8b780b462dce877afe9d0bea /bpkg/pkg-unpack.cxx
parentf5adc6c0ee7965abcad4cc73d0f36d1ed3cba3cc (diff)
Automatically cleanup package archive, directory on failure
Diffstat (limited to 'bpkg/pkg-unpack.cxx')
-rw-r--r--bpkg/pkg-unpack.cxx18
1 files changed, 7 insertions, 11 deletions
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;
}