2022-02-21 18:03:44 +01:00
|
|
|
#include "file.hpp"
|
2023-03-01 21:27:15 +00:00
|
|
|
|
|
|
|
#include "common.hpp"
|
2022-02-21 18:03:44 +01:00
|
|
|
#include "file_manager.hpp"
|
|
|
|
|
|
|
|
namespace big
|
|
|
|
{
|
2023-07-08 17:54:59 +02:00
|
|
|
file::file(const std::filesystem::path& file_path) :
|
|
|
|
m_file_path(file_path)
|
2022-02-21 18:03:44 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-07-08 17:54:59 +02:00
|
|
|
void file::operator=(const file& other)
|
2022-02-21 18:03:44 +01:00
|
|
|
{
|
2023-07-08 17:54:59 +02:00
|
|
|
m_file_path = other.m_file_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
file::operator std::filesystem::path()
|
|
|
|
{
|
|
|
|
return m_file_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
file::operator std::filesystem::path&()
|
|
|
|
{
|
|
|
|
return m_file_path;
|
2022-02-21 18:03:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool file::exists() const
|
|
|
|
{
|
|
|
|
return std::filesystem::exists(m_file_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::filesystem::path file::get_path() const
|
|
|
|
{
|
|
|
|
return m_file_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
file file::move(std::filesystem::path new_path)
|
|
|
|
{
|
|
|
|
if (new_path.is_relative())
|
|
|
|
new_path = m_file_path.parent_path() / new_path;
|
|
|
|
|
|
|
|
file_manager::ensure_file_can_be_created(new_path);
|
|
|
|
|
|
|
|
if (std::filesystem::exists(m_file_path))
|
|
|
|
std::filesystem::rename(m_file_path, new_path);
|
|
|
|
|
2023-03-01 21:27:15 +00:00
|
|
|
return {new_path};
|
2022-02-21 18:03:44 +01:00
|
|
|
}
|
|
|
|
}
|