| 645 | } |
| 646 | |
| 647 | Directory::Ptr Directory::make_new_subdir(const ACE_TString& t_name) |
| 648 | { |
| 649 | if (files_.find(t_name) != files_.end()) { |
| 650 | throw std::runtime_error("Can't create a directory with the same " |
| 651 | "name as an existing file."); |
| 652 | } |
| 653 | |
| 654 | ACE_TString logical(t_name.c_str(), |
| 655 | (std::min)(FSS_MAX_FILE_NAME, t_name.length())); |
| 656 | ACE_TString phys_prefix = add_entry(); |
| 657 | ACE_TString phys_base = b32h_encode(logical.c_str()); |
| 658 | |
| 659 | if (t_name.length() >= FSS_MAX_FILE_NAME) { |
| 660 | unsigned int& counter = long_names_[phys_prefix + phys_base]; |
| 661 | |
| 662 | if (counter == 99999) { |
| 663 | throw std::runtime_error("Long directory name out of range"); |
| 664 | } |
| 665 | |
| 666 | phys_base += ACE_TEXT(". X"); // snprintf will clobber the X with a 0 |
| 667 | ACE_TCHAR* buf = &phys_base[0] + phys_base.length() - 6; |
| 668 | ACE_OS::snprintf(buf, 6, ACE_TEXT("%05u"), counter++); |
| 669 | phys_base = phys_base.substr(0, phys_base.length() - 1); // trim the 0 |
| 670 | } |
| 671 | |
| 672 | ACE_TString phys = phys_prefix + phys_base; |
| 673 | dirs_[t_name] = phys; |
| 674 | { |
| 675 | CwdGuard cg(physical_dirname_); |
| 676 | |
| 677 | if (dds_mkdir(phys.c_str()) == -1) { |
| 678 | throw std::runtime_error("Can't create directory"); |
| 679 | } |
| 680 | |
| 681 | if ((phys_prefix.length() > 0 && dds_chdir(phys_prefix.c_str()) == -1) |
| 682 | || dds_chdir(phys_base.c_str()) == -1) { |
| 683 | dds_rmdir(phys.c_str()); |
| 684 | throw std::runtime_error("Can't change to newly created directory"); |
| 685 | } |
| 686 | |
| 687 | std::ofstream fn("_fullname"); |
| 688 | fn << t_name << '\n'; |
| 689 | } |
| 690 | return DCPS::make_rch<Directory>(physical_dirname_ + phys, t_name, rchandle_from(this)); |
| 691 | } |
| 692 | |
| 693 | ACE_TString Directory::add_entry() |
| 694 | { |
nothing calls this directly
no test coverage detected