--- src/eixTk/utils.cc +++ src/eixTk/utils.cc @@ -43,7 +43,7 @@ using namespace std; /** push_back every line of file into v. */ -bool pushback_lines(const char *file, vector *v, bool removed_empty) +bool pushback_lines_file(const char *file, vector *v, bool removed_empty) { string line; ifstream ifstr(file); @@ -71,14 +71,37 @@ return false; } +/** push_back every line of file or dir into v. */ +bool pushback_lines(const char *file, vector *v, bool removed_empty, bool recursive) +{ + static const char *files_exclude[] = { "..", "." , NULL }; + vector files; + string dir(file); + dir += "/"; + if(recursive && pushback_files(dir, files, files_exclude, false)) + { + bool rvalue=true; + for(vector::iterator it=files.begin(); + itc_str(), v, removed_empty)) + rvalue=false; + } + return rvalue; + } + else + return pushback_lines_file(file, v, removed_empty); +} + /** List of files in directory. * Pushed names of file in directory into string-vector if the don't match any * char * in given exlude list. * @param dir_path Path to directory * @param into pointer to vector of strings .. files get append here (with full path) * @param exclude list of char * that don't need to be put into vector + * @param onlyfiles consider only ordinary files * @return false if everything is ok */ -bool pushback_files(string &dir_path, vector &into, const char *exclude[]) +bool pushback_files(string &dir_path, vector &into, const char *exclude[], bool onlyfiles) { struct stat static_stat; DIR *dir = opendir(dir_path.c_str()); @@ -91,13 +114,19 @@ if(exclude) { char **_p = (char **)exclude; - while(*_p) /* Look if it's in exclude */ - if(strcmp(*(_p++), dir_entry->d_name) == 0) - continue; + for(;*_p;_p++) /* Look if it's in exclude */ + if(strcmp(*_p, dir_entry->d_name) == 0) + break; + if(*_p) + continue; + + } + if(onlyfiles) + { + if(stat((dir_path + dir_entry->d_name).c_str(), &static_stat) + || !S_ISREG(static_stat.st_mode)) + continue; } - if(stat((dir_path + dir_entry->d_name).c_str(), &static_stat) - || !S_ISREG(static_stat.st_mode)) - continue; into.push_back(dir_path + dir_entry->d_name); } closedir(dir); --- src/eixTk/utils.h +++ src/eixTk/utils.h @@ -32,8 +32,8 @@ #include #include -/** push_back every line of file into v. */ -bool pushback_lines(const char *file, std::vector *v, bool removed_empty = true); +/** push_back every line of file or dir into v. */ +bool pushback_lines(const char *file, std::vector *v, bool removed_empty = true, bool recursive = true); /** List of files in directory. * Pushed names of file in directory into string-vector if the don't match any @@ -41,8 +41,9 @@ * @param dir_path Path to directory * @param into pointer to vector of strings .. files get append here (with full path) * @param exlude list of char * that don't need to be put into vector + * @param onlyfiles consider only ordinary files * @return false if everything is ok */ -bool pushback_files(std::string &dir_path, std::vector &into, const char *exclude[]); +bool pushback_files(std::string &dir_path, std::vector &into, const char *exclude[], bool onlyfiles = true); /** Cycle through map using it, until it is it_end, append all values from it --- src/portage/conf/portagesettings.cc +++ src/portage/conf/portagesettings.cc @@ -42,36 +42,35 @@ using namespace std; -bool grab_masks(const char *file, Mask::Type type, MaskList *cat_map, vector *mask_vec) +bool grab_masks(const char *file, Mask::Type type, MaskList *cat_map, vector *mask_vec, bool recursive) { - ifstream mask_file(file); - if(mask_file.is_open()) { - string line; - while(getline(mask_file, line)) { - trim(&line); - if(line.size() == 0 || line[0] == '#') - continue; - try { - Mask *m = new Mask(line.c_str(), type); - OOM_ASSERT(m); - if(cat_map) { - cat_map->add(m); - } - else { - mask_vec->push_back(m); - } + vector lines; + if( ! pushback_lines(file, &lines, true, recursive)) + return false; + for(vector::iterator it=lines.begin(); itadd(m); } - catch(ExBasic e) { - cerr << "-- Invalid line in " << file << ": \"" << line << "\"" << endl - << " " << e.getMessage() << endl; + else { + mask_vec->push_back(m); } } - mask_file.close(); - return true; + catch(ExBasic e) { + cerr << "-- Invalid line in " << file << ": \"" << line << "\"" << endl + << " " << e.getMessage() << endl; + } } - return false; + return true; } + + + /** Key that should accumelate their content rathern then replace. */ static const char *default_accumulating_keys[] = { "USE", --- src/portage/conf/portagesettings.h +++ src/portage/conf/portagesettings.h @@ -45,16 +45,16 @@ class Package; /** Grab Masks from file and add to a category->vector mapping or to a vector. */ -bool grab_masks(const char *file, Mask::Type type, MaskList *cat_map, std::vector *mask_vec); +bool grab_masks(const char *file, Mask::Type type, MaskList *cat_map, std::vector *mask_vec, bool recursive=true); /** Grab Mask from file and add to category->vector. */ -inline bool grab_masks(const char *file, Mask::Type type, std::vector *mask_vec) { - return grab_masks(file, type, NULL , mask_vec); +inline bool grab_masks(const char *file, Mask::Type type, std::vector *mask_vec, bool recursive=true) { + return grab_masks(file, type, NULL , mask_vec, recursive); } /** Grab Mask from file and add to vector. */ -inline bool grab_masks(const char *file, Mask::Type type, MaskList *cat_map) { - return grab_masks(file, type, cat_map, NULL); +inline bool grab_masks(const char *file, Mask::Type type, MaskList *cat_map, bool recursive=true) { + return grab_masks(file, type, cat_map, NULL, recursive); } class PortageSettings;