| 174 | } |
| 175 | |
| 176 | void |
| 177 | LayoutEngine::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 |
no test coverage detected