Guest User

Untitled

a guest
Jul 24th, 2017
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #include <chrono>
  2. #include <iostream>
  3. #include <fstream>
  4. #include <mutex>
  5. #include <vector>
  6. #include <memory>
  7.  
  8. using namespace std;
  9.  
  10. static mutex theLock;
  11.  
  12. string exec(const char* cmd) {
  13. array<char, 1024> buffer;
  14. string result;
  15. shared_ptr<FILE> pipe(popen(cmd, "r"), pclose);
  16.  
  17. if (!pipe) {
  18. throw runtime_error("popen() failed!");
  19. }
  20.  
  21. while (!feof(pipe.get())) {
  22. if (fgets(buffer.data(), 1024, pipe.get()) != NULL) {
  23. result += buffer.data();
  24. }
  25. }
  26. return result;
  27. }
  28.  
  29.  
  30. void produce(const string &path) {
  31. string output = exec(("cd " + path + " && git pull 2>&1").c_str());
  32.  
  33. if(output != "Already up-to-date.\n") {
  34. cout << (output + '\n');
  35. }
  36. }
  37.  
  38.  
  39. int main() {
  40. ifstream repos;
  41. repos.open("repos");
  42.  
  43. if(!repos.is_open()) {
  44. cout << "Couldn't open repos file.";
  45. return -1;
  46. }
  47.  
  48. string line;
  49. vector<string> lines;
  50.  
  51.  
  52. while(getline(repos, line)) {
  53. if(line != "") {
  54. lines.push_back(line);
  55. }
  56. }
  57.  
  58. repos.close();
  59.  
  60. #pragma omp parallel for
  61. for(size_t i = 0; i < lines.size(); i++) {
  62. produce(lines[i]);
  63. }
  64.  
  65. return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment