From efd154a6af61e80be1b0c46642cefd73cc83d7ed Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 29 Sep 2015 13:04:29 +0200 Subject: Add auto_rmfile and auto_rmdir --- butl/filesystem.ixx | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'butl/filesystem.ixx') diff --git a/butl/filesystem.ixx b/butl/filesystem.ixx index 256cbba..3b72b4a 100644 --- a/butl/filesystem.ixx +++ b/butl/filesystem.ixx @@ -5,16 +5,47 @@ namespace butl { inline rmdir_status - try_rmdir_r (const dir_path& p) + try_rmdir_r (const dir_path& p, bool ignore_error) { bool e (dir_exists (p)); //@@ What if it exists but is not a directory? if (e) - rmdir_r (p); + rmdir_r (p, ignore_error); return e ? rmdir_status::success : rmdir_status::not_exist; } + // auto_rm + // + template + inline auto_rm

:: + auto_rm (auto_rm&& x) + : path_ (std::move (x.path_)) + { + x.cancel (); + } + + template + inline auto_rm

& auto_rm

:: + operator= (auto_rm&& x) + { + if (this != &x) + { + path_ = std::move (x.path_); + x.cancel (); + } + + return *this; + } + + template <> + inline auto_rm:: + ~auto_rm () {if (!path_.empty ()) try_rmfile (path_, true);} + + template <> + inline auto_rm:: + ~auto_rm () {if (!path_.empty ()) try_rmdir_r (path_, true);} + // permissions // inline permissions operator& (permissions x, permissions y) {return x &= y;} -- cgit v1.1