-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocalSource.hpp
More file actions
144 lines (125 loc) · 3.93 KB
/
Copy pathLocalSource.hpp
File metadata and controls
144 lines (125 loc) · 3.93 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#ifndef RUNCPP2_DATA_LOCAL_SOURCE_HPP
#define RUNCPP2_DATA_LOCAL_SOURCE_HPP
#include "runcpp2/LibYAML_Wrapper.hpp"
#include "runcpp2/ParseUtil.hpp"
#include "DSResult/DSResult.hpp"
#include "ssLogger/ssLog.hpp"
#include <string>
#include <vector>
namespace runcpp2
{
namespace Data
{
enum class LocalCopyMode;
}
}
namespace
{
std::string CopyModeToString(runcpp2::Data::LocalCopyMode mode);
runcpp2::Data::LocalCopyMode StringToCopyMode(const std::string& str, bool& outSuccess);
}
namespace runcpp2
{
namespace Data
{
enum class LocalCopyMode
{
Auto,
Symlink,
Hardlink,
Copy,
Count
};
struct LocalSource
{
std::string Path;
LocalCopyMode CopyMode = LocalCopyMode::Auto;
inline bool ParseYAML_Node(YAML::ConstNodePtr node)
{
std::vector<NodeRequirement> requirements =
{
NodeRequirement("Path", YAML::NodeType::Scalar, true, false)
};
if(!CheckNodeRequirements(node, requirements))
{
ssLOG_ERROR("LocalSource: Failed to meet requirements");
return false;
}
Path = node->GetMapValueScalar<std::string>("Path").DS_TRY_ACT(return false);
if(ExistAndHasChild(node, "CopyMode"))
{
bool success = false;
CopyMode = StringToCopyMode(node->GetMapValueScalar<std::string>("CopyMode")
.DefaultOr(),
success);
if(!success)
return false;
}
return true;
}
inline std::string ToString(std::string indentation) const
{
std::string out;
out += indentation + "Local:\n";
out += indentation + " Path: " + GetEscapedYAMLString(Path) + "\n";
out += indentation + " CopyMode: " + CopyModeToString(CopyMode) + "\n";
return out;
}
inline bool Equals(const LocalSource& other) const
{
return Path == other.Path && CopyMode == other.CopyMode;
}
};
}
}
namespace
{
static_assert( static_cast<int>(runcpp2::Data::LocalCopyMode::Count) == 4,
"Update CopyModeToString when adding new LocalCopyMode values");
std::string CopyModeToString(runcpp2::Data::LocalCopyMode mode)
{
switch(mode)
{
case runcpp2::Data::LocalCopyMode::Auto:
return "Auto";
case runcpp2::Data::LocalCopyMode::Symlink:
return "Symlink";
case runcpp2::Data::LocalCopyMode::Hardlink:
return "Hardlink";
case runcpp2::Data::LocalCopyMode::Copy:
return "Copy";
default:
ssLOG_ERROR("Unknown LocalCopyMode value");
return "Auto";
}
}
static_assert( static_cast<int>(runcpp2::Data::LocalCopyMode::Count) == 4,
"Update StringToCopyMode when adding new LocalCopyMode values");
runcpp2::Data::LocalCopyMode StringToCopyMode(const std::string& str, bool& outSuccess)
{
if(str == "Auto")
{
outSuccess = true;
return runcpp2::Data::LocalCopyMode::Auto;
}
else if(str == "Symlink")
{
outSuccess = true;
return runcpp2::Data::LocalCopyMode::Symlink;
}
else if(str == "Hardlink")
{
outSuccess = true;
return runcpp2::Data::LocalCopyMode::Hardlink;
}
else if(str == "Copy")
{
outSuccess = true;
return runcpp2::Data::LocalCopyMode::Copy;
}
ssLOG_ERROR("Invalid LocalCopyMode value: " << str);
outSuccess = false;
return runcpp2::Data::LocalCopyMode::Auto;
}
}
#endif