diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2018-05-14 14:10:56 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2018-05-14 16:54:16 +0300 |
commit | 2df57d72b65012674e6bc64dec66d9b3fd7f993b (patch) | |
tree | 81c893c0b745145d9a3779b9ce3fb41c57e17956 /bpkg/pkg-disfigure.cxx | |
parent | 1ddbf3409f76f0dd91a9402e602bc1ea1b12f8cd (diff) |
Fallback to output directory removal for --keep-out on disfigure failure
Diffstat (limited to 'bpkg/pkg-disfigure.cxx')
-rw-r--r-- | bpkg/pkg-disfigure.cxx | 41 |
1 files changed, 38 insertions, 3 deletions
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, |