void getRecursiveDirList(const String& baseDir, StringVec& dirVec, const StringVec& ignoreList)
{ 
  DIR* dir = opendir(baseDir.c_str());
  if (!dir)
    return;
    
  dirVec.push_back(baseDir);

  struct dirent* entry;
  while ((entry = readdir(dir))) {
    if (entry->d_type == DT_DIR) {
      String path = joinPaths(baseDir, entry->d_name);
         
      if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, ".."))
        continue;
        
      if (matchWildcardList(entry->d_name, ignoreList))
        continue;
      
      getRecursiveDirList(path, dirVec, ignoreList);
    }
  }

  closedir(dir);
}
Exemplo n.º 2
0
static String expandRecursivePath(const String& path, const String& prefix, const VariableCollectionHierarchy& vch)
{
  // Check if recursive expansion is necessary
  if (!strEndsWith(path, "/**"))
    return addPrefixQuoted(path, prefix, vch);
  
  // Remove the pesky /** ending
  String fixedPath = path.substr(0, path.length() - 3);
  
  // Expand the path and get an absolute project path
  String expandedPath = vch.expand(fixedPath);
  String projectPath = vch.getValue("PROJECT_DIR");
  
  // Make an absolute path
  String absPath = joinPaths(projectPath, expandedPath);
  
  // Get a list of subdirectories to ignore
  StringVec ignoreList;
  vch.getValue("EXCLUDED_RECURSIVE_SEARCH_PATH_SUBDIRECTORIES", ignoreList);

  // Get recursive paths
  StringVec dirVec;
  getRecursiveDirList(absPath, dirVec, ignoreList);
  
  // Sort the paths such that they are in breadth-first, alphabetic order
  std::sort(dirVec.begin(), dirVec.end(), compare_nocase_breadth_first);

  // Substitute back the original form of the path (which likely contains variables)
  String ret;
  for (unsigned i = 0; i < dirVec.size(); i++) {
    dirVec[i].replace(0, absPath.length(), fixedPath);
    ret += addPrefixQuoted(dirVec[i], prefix, vch);
  }

  // Check that the recursive expansion succeeded
  if (dirVec.empty()) {
    SBLog::info() << "Failed recursive expansion of \"" << absPath << "\". Path does not exist." << std::endl;
    return "";
  } else { 
    return ret;
  }
}