| 666 | } |
| 667 | |
| 668 | void create_lrl_file(std::string& lrlpath, |
| 669 | std::string repl_name, |
| 670 | std::string master_name, |
| 671 | std::string repl_type) |
| 672 | { |
| 673 | // First, load the lrl file into memory. |
| 674 | // Modify string path to rename it to the replication machine's name |
| 675 | size_t parent_dir_loc = lrlpath.find_last_of("/") + 1; |
| 676 | if (parent_dir_loc >= lrlpath.size()) |
| 677 | { |
| 678 | std::cerr << "Path doesn't have / inside?" << std::endl; |
| 679 | } |
| 680 | std::string new_path = lrlpath.substr(0, parent_dir_loc) + repl_name + ".lrl"; |
| 681 | |
| 682 | std::ifstream lrlstream(lrlpath.c_str()); |
| 683 | std::ofstream phys_lrl(new_path.c_str()); |
| 684 | |
| 685 | std::cerr << "orig lrlpath was: " << lrlpath << std::endl; |
| 686 | std::cerr << "create_lrl_file here: " << new_path << std::endl; |
| 687 | lrlpath = new_path; |
| 688 | |
| 689 | if(!lrlstream.is_open()) { |
| 690 | throw LRLError(lrlpath, 0, "cannot open file"); |
| 691 | } |
| 692 | int lineno = 0; |
| 693 | while(!lrlstream.eof()) { |
| 694 | std::string line; |
| 695 | std::getline(lrlstream, line); |
| 696 | lineno++; |
| 697 | |
| 698 | // Parse the line that we just read. First strip off comments. |
| 699 | size_t pos = line.find_first_of('#'); |
| 700 | if(pos != std::string::npos) { |
| 701 | line.resize(pos); |
| 702 | } |
| 703 | std::istringstream liness(line); |
| 704 | |
| 705 | std::string tok; |
| 706 | if(liness >> tok) { |
| 707 | |
| 708 | /* rewrite the name here */ |
| 709 | if(tok == "cluster") { |
| 710 | if(!(liness >> tok)) { |
| 711 | throw LRLError(lrlpath, lineno, "Invalid cluster nodes line"); |
| 712 | } |
| 713 | |
| 714 | /* cleave cluster is implied */ |
| 715 | phys_lrl << "#" << line << std::endl; |
| 716 | } |
| 717 | else if(tok == "name") { |
| 718 | if(!(liness >> tok)) { |
| 719 | throw LRLError(lrlpath, lineno, "missing database name"); |
| 720 | } |
| 721 | phys_lrl << "name " << repl_name << std::endl; |
| 722 | |
| 723 | } |
| 724 | else |
| 725 | { |
no test coverage detected