MCPcopy Create free account
hub / github.com/apache/trafficserver / create_runroot

Method create_runroot

src/traffic_layout/engine.cc:176–352  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

174}
175
176void
177LayoutEngine::create_runroot()
178{
179 // set up options
180 std::string path = path_handler(arguments.get("path").value(), true, _argv[0]);
181 if (path.empty()) {
182 ink_error("Path not valid for creating");
183 status_code = EX_SOFTWARE;
184 return;
185 }
186 bool force_flag = arguments.get("force");
187 bool abs_flag = arguments.get("absolute");
188 std::string layout_file = arguments.get("layout").value();
189 if (layout_file.find("runroot.yaml") != std::string::npos) {
190 ink_error(
191 "'runroot.yaml' is a potentially dangerous name for '--layout' option.\nPlease set other name to the file for '--layout'");
192 status_code = EX_SOFTWARE;
193 return;
194 }
195 // deal with the copy style
196 CopyStyle copy_style = HARD;
197 std::string style = arguments.get("copy-style").value();
198 if (!style.empty()) {
199 transform(style.begin(), style.end(), style.begin(), ::tolower);
200 if (style == "full") {
201 copy_style = FULL;
202 } else if (style == "soft") {
203 copy_style = SOFT;
204 } else if (style == "hard") {
205 copy_style = HARD;
206 } else {
207 ink_error("Unknown copy style: '%s'", style.c_str());
208 status_code = EX_USAGE;
209 return;
210 }
211 }
212 std::string original_root = Layout::get()->prefix;
213 const std::string &ts_runroot = path;
214 // check for existing runroot to use rather than create new one
215 if (!force_flag && exists(Layout::relative_to(ts_runroot, "runroot.yaml"))) {
216 std::cout << "Using existing runroot...\n"
217 "Please remove the old runroot if new runroot is needed"
218 << std::endl;
219 return;
220 }
221 if (!force_flag && !check_parent_path(ts_runroot).empty()) {
222 ink_error("Cannot create runroot inside another runroot");
223 status_code = EX_SOFTWARE;
224 return;
225 }
226
227 std::cout << "creating runroot - " + ts_runroot << std::endl;
228
229 // check if directory is empty when --force is not used
230 if (is_directory(ts_runroot) && !force_flag) {
231 empty_check_directory = ts_runroot;
232 if (ftw(ts_runroot.c_str(), check_directory_empty, OPEN_MAX_FILE) != 0) {
233 // if the directory is not empty, check for valid Y/N

Callers 1

mainFunction · 0.80

Calls 15

path_handlerFunction · 0.85
ink_errorFunction · 0.85
check_parent_pathFunction · 0.85
is_directoryFunction · 0.85
LoadFileFunction · 0.85
ink_warningFunction · 0.85
ink_noticeFunction · 0.85
copy_directoryFunction · 0.85
badMethod · 0.80
create_directoryFunction · 0.70
getFunction · 0.50
existsFunction · 0.50

Tested by

no test coverage detected