From 58d2fac91d0da7312e3ef147b6b290ea16031da8 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Mon, 16 Nov 2015 05:53:10 -0500 Subject: [PATCH] AutoDelete: Add default constructor with deletion disabled --- src/libstore/build.cc | 2 +- src/libutil/util.cc | 8 ++++++++ src/libutil/util.hh | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/libstore/build.cc b/src/libstore/build.cc index 6f662f81d..6112d528c 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -2534,7 +2534,7 @@ void DerivationGoal::runChild() Path sandboxFile = drvPath + ".sb"; if (pathExists(sandboxFile)) deletePath(sandboxFile); - autoDelSandbox = AutoDelete(sandboxFile); + autoDelSandbox.reset(sandboxFile, false); writeFile(sandboxFile, sandboxProfile); diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 27116fd18..84f578eec 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -599,6 +599,8 @@ string drainFD(int fd) ////////////////////////////////////////////////////////////////////// +AutoDelete::AutoDelete() : del{false} {} + AutoDelete::AutoDelete(const string & p, bool recursive) : path(p) { del = true; @@ -626,6 +628,12 @@ void AutoDelete::cancel() del = false; } +void AutoDelete::reset(const Path & p, bool recursive = true) { + this-> p = p; + this->recursive = recursive; + del = true; +} + ////////////////////////////////////////////////////////////////////// diff --git a/src/libutil/util.hh b/src/libutil/util.hh index 23d01e9a6..f4026a0a8 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -199,9 +199,11 @@ class AutoDelete bool del; bool recursive; public: + AutoDelete(); AutoDelete(const Path & p, bool recursive = true); ~AutoDelete(); void cancel(); + void reset(const Path & p, bool recursive = true); operator Path() const { return path; } };