/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * Copyright 2022, Danny Robson */ #include "./scoped.hpp" #include using cruft::fs::scoped_dir; /////////////////////////////////////////////////////////////////////////////// scoped_dir::scoped_dir (std::filesystem::path const &_path) : scoped_dir (std::filesystem::path (_path)) {} //----------------------------------------------------------------------------- scoped_dir::scoped_dir (std::filesystem::path &&_path) : m_path (std::move (_path)) { CHECK (std::filesystem::is_directory (*m_path)); } /////////////////////////////////////////////////////////////////////////////// scoped_dir::~scoped_dir () { if (m_path) std::filesystem::remove_all (*m_path); } /////////////////////////////////////////////////////////////////////////////// std::filesystem::path const & scoped_dir::operator* () const & { return *m_path; } //----------------------------------------------------------------------------- std::filesystem::path const* scoped_dir::operator-> () const & { return &*m_path; }