From 92dda992ee07d8de047406f5ba227483bdb5eed5 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 27 Sep 2022 14:55:49 +1000 Subject: [PATCH] fs/scoped: add scoped_dir convenience function --- fs/scoped.cpp | 9 +++++++++ fs/scoped.hpp | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/fs/scoped.cpp b/fs/scoped.cpp index e58d9145..961cc3cb 100644 --- a/fs/scoped.cpp +++ b/fs/scoped.cpp @@ -7,6 +7,7 @@ */ #include "./scoped.hpp" +#include "./tmp.hpp" #include @@ -90,3 +91,11 @@ scoped_dir::scoped_dir (std::filesystem::path &&_path) { CHECK (std::filesystem::is_directory (get ())); } + + +/////////////////////////////////////////////////////////////////////////////// +cruft::fs::scoped_dir +cruft::fs::scoped_tmpdir () +{ + return scoped_dir (cruft::fs::mktmpdir ()); +} \ No newline at end of file diff --git a/fs/scoped.hpp b/fs/scoped.hpp index c8440f25..18d1b2b5 100644 --- a/fs/scoped.hpp +++ b/fs/scoped.hpp @@ -50,4 +50,8 @@ namespace cruft::fs { using scoped_path::scoped_path; }; + + + /// A convenience function equivalent to `scoped_dir(maketmpdir())` + scoped_dir scoped_tmpdir (void); } \ No newline at end of file