aboutsummaryrefslogtreecommitdiff
path: root/butl/filesystem.ixx
diff options
context:
space:
mode:
Diffstat (limited to 'butl/filesystem.ixx')
-rw-r--r--butl/filesystem.ixx35
1 files changed, 33 insertions, 2 deletions
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 <typename P>
+ inline auto_rm<P>::
+ auto_rm (auto_rm&& x)
+ : path_ (std::move (x.path_))
+ {
+ x.cancel ();
+ }
+
+ template <typename P>
+ inline auto_rm<P>& auto_rm<P>::
+ operator= (auto_rm&& x)
+ {
+ if (this != &x)
+ {
+ path_ = std::move (x.path_);
+ x.cancel ();
+ }
+
+ return *this;
+ }
+
+ template <>
+ inline auto_rm<path>::
+ ~auto_rm () {if (!path_.empty ()) try_rmfile (path_, true);}
+
+ template <>
+ inline auto_rm<dir_path>::
+ ~auto_rm () {if (!path_.empty ()) try_rmdir_r (path_, true);}
+
// permissions
//
inline permissions operator& (permissions x, permissions y) {return x &= y;}