52 lines
1.3 KiB
C++
52 lines
1.3 KiB
C++
/*
|
|
* 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 <danny@nerdcruft.net>
|
|
*/
|
|
|
|
#include "./scoped.hpp"
|
|
|
|
#include <cruft/util/debug/assert.hpp>
|
|
|
|
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;
|
|
}
|