From 2df57d72b65012674e6bc64dec66d9b3fd7f993b Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 14 May 2018 14:10:56 +0300 Subject: Fallback to output directory removal for --keep-out on disfigure failure --- bpkg/pkg-disfigure.cxx | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) (limited to 'bpkg/pkg-disfigure.cxx') diff --git a/bpkg/pkg-disfigure.cxx b/bpkg/pkg-disfigure.cxx index 4a0bd72..0e82f18 100644 --- a/bpkg/pkg-disfigure.cxx +++ b/bpkg/pkg-disfigure.cxx @@ -123,10 +123,45 @@ namespace bpkg // So in this case we just remove the output directory manually // rather then running 'b clean disfigure'. // - if (clean && p->external ()) - rm_r (out_root); + // It may also happen that we can not disfigure the external + // package' output directory (the source directory have moved, etc.). + // If that's the case, then we fallback to the output directory + // removal. + // + if (p->external ()) + { + if (!clean) + { + auto_fd dev_null (open_dev_null ()); + + // Redirect STDERR to /dev/null. Note that we don't expect + // anything to be written to STDOUT. + // + process pr (start_b (o, + 1 /* stdout */, dev_null /* stderr */, + verb_b::quiet, + bspec)); + + // If the disfigure meta-operation failed then we report the + // abnormal termination and fallback to the output directory + // removal otherwise. + // + if (!pr.wait ()) + { + const process_exit& e (*pr.exit); + + if (!e.normal ()) + fail << "process " << name_b (o) << " " << e; + + clean = true; + } + } + + if (clean) + rm_r (out_root); + } else - run_b (o, c, bspec, verb_b::quiet); + run_b (o, verb_b::quiet, bspec); } // Make sure the out directory is gone unless it is the same as src, -- cgit v1.1