forked from organicmaps/organicmaps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscoped_dir.cpp
70 lines (62 loc) · 1.73 KB
/
scoped_dir.cpp
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "platform/platform_tests_support/scoped_dir.hpp"
#include "testing/testing.hpp"
#include "base/file_name_utils.hpp"
#include "base/logging.hpp"
#include <sstream>
namespace platform
{
namespace tests_support
{
ScopedDir::ScopedDir(std::string const & relativePath)
: m_fullPath(base::JoinPath(GetPlatform().WritableDir(), relativePath))
, m_relativePath(relativePath)
, m_reset(false)
{
Platform::EError ret = Platform::MkDir(GetFullPath());
switch (ret)
{
case Platform::ERR_OK:
break;
case Platform::ERR_FILE_ALREADY_EXISTS:
Platform::EFileType type;
TEST_EQUAL(Platform::ERR_OK, Platform::GetFileType(GetFullPath(), type), ());
TEST_EQUAL(Platform::EFileType::Directory, type, ());
break;
default:
TEST(false, ("Can't create directory:", GetFullPath(), "error:", ret));
break;
}
}
ScopedDir::ScopedDir(ScopedDir const & parent, std::string const & name)
: ScopedDir(base::JoinPath(parent.GetRelativePath(), name))
{
}
ScopedDir::~ScopedDir()
{
if (m_reset)
return;
std::string const fullPath = GetFullPath();
Platform::EError ret = Platform::RmDir(fullPath);
switch (ret)
{
case Platform::ERR_OK:
break;
case Platform::ERR_FILE_DOES_NOT_EXIST:
LOG(LERROR, (fullPath, "was deleted before destruction of ScopedDir."));
break;
case Platform::ERR_DIRECTORY_NOT_EMPTY:
LOG(LERROR, ("There are files in", fullPath));
break;
default:
LOG(LERROR, ("Platform::RmDir() error for", fullPath, ":", ret));
break;
}
}
std::string DebugPrint(ScopedDir const & dir)
{
std::ostringstream os;
os << "ScopedDir [" << dir.GetFullPath() << "]";
return os.str();
}
} // namespace tests_support
} // namespace platform