diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-09-29 13:04:29 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-09-29 13:04:29 +0200 |
commit | efd154a6af61e80be1b0c46642cefd73cc83d7ed (patch) | |
tree | f41400d27727800d7f72317f80ee8e43285792b4 /butl/filesystem.ixx | |
parent | cdc67ad0cf1e102568396b0649dd18ea1223d785 (diff) |
Add auto_rmfile and auto_rmdir
Diffstat (limited to 'butl/filesystem.ixx')
-rw-r--r-- | butl/filesystem.ixx | 35 |
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;} |