aboutsummaryrefslogtreecommitdiff
path: root/zencore/testutils.cpp
blob: dbc3ab5af6093db841b2fa2c07de2744359dea6e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright Epic Games, Inc. All Rights Reserved.

#include "zencore/testutils.h"
#include <zencore/session.h>
#include "zencore/string.h"

#include <atomic>

namespace zen {

static std::atomic<int> Sequence{0};

std::filesystem::path
CreateTemporaryDirectory()
{
	std::error_code Ec;

	std::filesystem::path DirPath = std::filesystem::temp_directory_path() / GetSessionIdString() / IntNum(++Sequence).c_str();
	std::filesystem::remove_all(DirPath, Ec);
	std::filesystem::create_directories(DirPath);

	return DirPath;
}

ScopedTemporaryDirectory::ScopedTemporaryDirectory() : m_RootPath(CreateTemporaryDirectory())
{
}

ScopedTemporaryDirectory::ScopedTemporaryDirectory(std::filesystem::path Directory) : m_RootPath(Directory)
{
	std::error_code Ec;
	std::filesystem::remove_all(Directory, Ec);
	std::filesystem::create_directories(Directory);
}

ScopedTemporaryDirectory::~ScopedTemporaryDirectory()
{
	std::error_code Ec;
	std::filesystem::remove_all(m_RootPath, Ec);
}

}  // namespace zen