MCPcopy Create free account
hub / github.com/OpenDDS/OpenDDS / make_new_subdir

Method make_new_subdir

dds/DCPS/FileSystemStorage.cpp:647–691  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

645}
646
647Directory::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
693ACE_TString Directory::add_entry()
694{

Callers

nothing calls this directly

Calls 8

b32h_encodeFunction · 0.85
dds_mkdirFunction · 0.85
dds_chdirFunction · 0.85
dds_rmdirFunction · 0.85
rchandle_fromFunction · 0.85
findMethod · 0.45
endMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected