FOSSology  4.4.0
Open Source License Compliance by Open Source Software
directoryScan.cc
Go to the documentation of this file.
1 /*
2  SPDX-FileCopyrightText: © 2019 Siemens AG
3  Author: Gaurav Mishra <mishra.gaurav@siemens.com>
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
13 #include "directoryScan.hpp"
14 
15 using namespace std;
16 namespace fs = boost::filesystem;
17 
18 void scanDirectory(const CopyrightState& state, const bool json,
19  const string directoryPath)
20 {
21  fs::recursive_directory_iterator dirIterator(directoryPath);
22  fs::recursive_directory_iterator end;
23 
24  vector<string> filePaths;
25 
26  for (fs::path const &p : boost::make_iterator_range(dirIterator, {}))
27  {
28  if (fs::is_directory(p))
29  {
30  // Can not do anything with a directory
31  continue;
32  }
33  // Store the paths in a vector as of now since we can not `#pragma omp for`
34  // on recursive_directory_iterator
35  filePaths.push_back(p.string());
36  }
37  const unsigned long filePathsSize = filePaths.size();
38  bool printComma = false;
39 
40  if (json)
41  {
42  cout << "[" << endl;
43  }
44 
45 #pragma omp parallel
46  {
47 #pragma omp for
48  for (unsigned int i = 0; i < filePathsSize; i++)
49  {
50  string fileName = filePaths[i];
51  pair<string, list<match>> scanResult = processSingleFile(state, fileName);
52  if (json)
53  {
54  appendToJson(fileName, scanResult, printComma);
55  }
56  else
57  {
58  printResultToStdout(fileName, scanResult);
59  }
60  }
61  }
62  if (json)
63  {
64  cout << endl << "]" << endl;
65  }
66 }
Holds information about state of one agent.
pair< string, list< match > > processSingleFile(const CopyrightState &state, const string fileName)
void appendToJson(const std::string fileName, const std::pair< string, list< match >> resultPair, bool &printComma)
void printResultToStdout(const std::string fileName, const std::pair< string, list< match >> resultPair)
void scanDirectory(const bool json, const string &directoryPath)