aboutsummaryrefslogtreecommitdiff
path: root/bpkg/pkg-disfigure.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'bpkg/pkg-disfigure.cxx')
-rw-r--r--bpkg/pkg-disfigure.cxx111
1 files changed, 63 insertions, 48 deletions
diff --git a/bpkg/pkg-disfigure.cxx b/bpkg/pkg-disfigure.cxx
index 1c356f0..7ddd418 100644
--- a/bpkg/pkg-disfigure.cxx
+++ b/bpkg/pkg-disfigure.cxx
@@ -20,6 +20,7 @@ namespace bpkg
transaction& t,
const shared_ptr<selected_package>& p,
bool clean,
+ bool disfigure,
bool simulate)
{
assert (p->state == package_state::configured ||
@@ -94,9 +95,13 @@ namespace bpkg
if (p->state == package_state::configured)
{
if (clean)
- bspec = "clean('" + rep + "') ";
+ bspec = "clean('" + rep + "')";
- bspec += "disfigure('" + rep + "')";
+ if (disfigure)
+ {
+ bspec += (bspec.empty () ? "" : " ");
+ bspec += "disfigure('" + rep + "')";
+ }
}
else
{
@@ -111,65 +116,71 @@ namespace bpkg
"')";
}
- l4 ([&]{trace << "buildspec: " << bspec;});
-
- // Disfigure.
+ // Clean and/or disfigure.
//
+ if (!bspec.empty () && exists (out_root))
try
{
- if (exists (out_root))
+ l4 ([&]{trace << "buildspec: " << bspec;});
+
+ // Note that for external packages out_root is only the output
+ // directory. It is also possible that the buildfiles in the source
+ // directory have changed in a way that they don't clean everything.
+ // So in this case we just remove the output directory manually rather
+ // then running 'b clean disfigure'.
+ //
+ // It may also happen that we cannot 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 ())
{
- // Note that for external packages this is just the output
- // directory. It is also possible that the buildfiles in the source
- // directory have changed in a way that they don't clean everything.
- // So in this case we just remove the output directory manually
- // rather then running 'b clean disfigure'.
+ // clean disfigure
//
- // 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.
+ // true true -- wipe the directory
+ // true false -- try to clean, ignore if failed
+ // false true -- try to disfigure, fallback to wipe if failed
+ // false false -- never get here (bspec is empty)
//
- if (p->external ())
+
+ if (!clean || !disfigure)
{
- if (!clean)
+ auto_fd dev_null (open_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 ())
{
- auto_fd dev_null (open_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;
- }
- }
+ const process_exit& e (*pr.exit);
+
+ if (!e.normal ())
+ fail << "process " << name_b (o) << " " << e;
- if (clean)
- rm_r (out_root);
+ clean = true;
+ }
}
- else
- run_b (o, verb_b::quiet, bspec);
+
+ if (clean && disfigure)
+ rm_r (out_root);
}
+ else
+ run_b (o, verb_b::quiet, bspec);
// Make sure the out directory is gone unless it is the same as src,
- // or we didn't clean it.
+ // or we didn't clean or disfigure it.
//
- if (out_root != src_root && clean && exists (out_root))
+ if (out_root != src_root && clean && disfigure && exists (out_root))
fail << "package output directory " << out_root << " still exists";
}
catch (const failed&)
@@ -223,7 +234,11 @@ namespace bpkg
// Commits the transaction.
//
- pkg_disfigure (o, db, t, p, !o.keep_out (), false /* simulate */);
+ pkg_disfigure (o, db, t,
+ p,
+ !o.keep_out () /* clean */,
+ !o.keep_config () /* disfigure */,
+ false /* simulate */);
assert (p->state == package_state::unpacked ||
p->state == package_state::transient);