aboutsummaryrefslogtreecommitdiff
path: root/libbutl/filesystem.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-07-21 09:36:05 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-07-21 09:36:05 +0200
commit811d4229c196c1c98ff865fdfd981ef2908f6d8b (patch)
tree7ed4833d43b575b64ebb4e300a37320e6230d8b3 /libbutl/filesystem.hxx
parent41da9fabee47c81c1c8f59fe6616f24fc1b21294 (diff)
Improve auto_rm
Diffstat (limited to 'libbutl/filesystem.hxx')
-rw-r--r--libbutl/filesystem.hxx20
1 files changed, 9 insertions, 11 deletions
diff --git a/libbutl/filesystem.hxx b/libbutl/filesystem.hxx
index e23fcd3..9bf6f0c 100644
--- a/libbutl/filesystem.hxx
+++ b/libbutl/filesystem.hxx
@@ -157,21 +157,22 @@ namespace butl
LIBBUTL_SYMEXPORT rmfile_status
try_rmfile (const path&, bool ignore_error = false);
- // Automatically try to remove the path on destruction unless cancelled.
- // Since the non-cancelled destruction will normally happen as a result
- // of an exception, the failure to remove the path is silently ignored.
+ // Automatically try to remove a non-empty the path on destruction unless
+ // cancelled. Since the non-cancelled destruction will normally happen as a
+ // result of an exception, the failure to remove the path is silently
+ // ignored.
//
template <typename P>
struct auto_rm
{
+ P path;
+ bool active;
+
explicit
- auto_rm (P p = P ()): path_ (std::move (p)) {}
+ auto_rm (P p = P (), bool a = true): path (std::move (p)), active (a) {}
void
- cancel () {path_ = P ();}
-
- const P&
- path () const {return path_;}
+ cancel () {active = false;}
// Movable-only type. Move-assignment cancels the lhs object.
//
@@ -181,9 +182,6 @@ namespace butl
auto_rm& operator= (const auto_rm&) = delete;
~auto_rm ();
-
- private:
- P path_;
};
using auto_rmfile = auto_rm<path>;