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

Method remove_runroot

src/traffic_layout/engine.cc:355–417  ·  view source on GitHub ↗

the function for removing the runroot

Source from the content-addressed store, hash-verified

353
354// the function for removing the runroot
355void
356LayoutEngine::remove_runroot()
357{
358 std::string path = path_handler(arguments.get("path").value(), false, _argv[0]);
359 // check validity of the path
360 if (path.empty()) {
361 ink_error("Path not valid (runroot.yaml not found)");
362 status_code = EX_IOERR;
363 return;
364 }
365
366 std::string &clean_root = path;
367 append_slash(clean_root);
368
369 if (arguments.get("force")) {
370 // the force remove
371 std::cout << "Forcing removing runroot ..." << std::endl;
372 if (!remove_directory(clean_root)) {
373 ink_warning("Failed force removing runroot '%s' - %s", clean_root.c_str(), strerror(errno));
374 }
375 } else {
376 // handle the map and deleting of each directories specified in the yml file
377 RunrootMapType map = runroot_map(Layout::relative_to(clean_root, "runroot.yaml"));
378 map.erase(LAYOUT_PREFIX);
379 map.erase(LAYOUT_EXEC_PREFIX);
380 // get current working directory
381 std::string cur_working_dir = "";
382 char cwd[PATH_MAX];
383 if (getcwd(cwd, sizeof(cwd)) == nullptr) {
384 ink_warning("unexpected failure from getcwd() - %s", strerror(errno));
385 } else {
386 cur_working_dir = cwd;
387 }
388 for (const auto &it : map) {
389 std::string dir = it.second;
390 if (dir.size() > clean_root.size() && dir.substr(0, clean_root.size()) == clean_root) {
391 append_slash(dir);
392 // get the directory to remove: prefix/etc/trafficserver -> prefix/etc
393 dir = dir.substr(0, dir.substr(clean_root.size()).find_first_of("/") + clean_root.size());
394 }
395 // don't remove cwd
396 if (cur_working_dir != dir) {
397 remove_directory(dir);
398 } else {
399 // if we are at this directory, remove files inside
400 remove_inside_directory(dir);
401 }
402 }
403 // remove yaml file
404 std::string yaml_file = Layout::relative_to(clean_root, "runroot.yaml");
405 if (remove(yaml_file.c_str()) != 0) {
406 ink_notice("unable to delete runroot.yaml - %s", strerror(errno));
407 }
408
409 append_slash(cur_working_dir);
410 if (cur_working_dir.find(clean_root) != 0) {
411 // if cwd is not runroot and runroot is empty, remove it
412 if (remove(clean_root.c_str()) != 0) {

Callers 1

mainFunction · 0.80

Calls 15

path_handlerFunction · 0.85
ink_errorFunction · 0.85
remove_directoryFunction · 0.85
ink_warningFunction · 0.85
runroot_mapFunction · 0.85
remove_inside_directoryFunction · 0.85
removeFunction · 0.85
ink_noticeFunction · 0.85
append_slashFunction · 0.70
valueMethod · 0.45
getMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected