diff --git a/pedi.cpp b/pedi.cpp index 7507efa685d70a29cd950257e5b39480e7a96ca0..16455c6b506d73b7de0a121a6e78d5feb0ceafc1 100644 --- a/pedi.cpp +++ b/pedi.cpp @@ -17,6 +17,33 @@ using namespace std; +int mkpath(const string& path, const mode_t& mode) +{ + auto s=path; + auto pos=(size_t)0; + + if(s[s.size()-1]!='/') + { + // force trailing / so we can handle everything in loop + s+='/'; + } + + // Caution! side effect in the while loop! + while((pos=s.find_first_of('/',pos))!=string::npos) + { + auto dir=s.substr(0,pos++); + if(dir.size()==0) + continue; // if leading / first time is 0 length + + auto mdret=mkdir(dir.c_str(),mode); + if(mdret!=0 && errno!=EEXIST) + { + return mdret; + } + } + return 0; +} + // Parse some options for the transform static struct option long_options[] = { {"setup", no_argument, 0, 's'}, @@ -516,21 +543,6 @@ void read_configs() auto orig_configfile=trimmed(mf)+".config"; read_config(orig_configfile, my_options.install_dir, my_options.labels); - -#if 0 - for(const auto & s : manifest_files) - { - string install_dir, labels; - auto configfile=trimmed(s)+".config"; - read_config(configfile, install_dir, labels); - - if(my_options.install_dir != install_dir || my_options.labels != labels) - { - cerr<<"Mismatch configuration in "<<orig_configfile<<" and "<<configfile<<endl; - exit(1); - } - } -#endif } auto previously_had_pedi_root=false; @@ -640,6 +652,12 @@ void finish() { if(!configs_read || previously_had_pedi_root) { + auto mkpath_err=mkpath(my_options.install_dir, S_IRUSR | S_IWUSR | S_IXUSR); + if(mkpath_err != 0 ) + { + cout << " Could not make directory " << my_options.install_dir << endl; + exit(1); + } ofstream o(my_options.install_dir+"/"+".pedi_root"); if(my_options.verbose) cout<<"Writing pedi_root file."<<endl;