excludetools.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include "kind.h"
  2. #include "Exception.h"
  3. #include "FileName.h"
  4. #include "filetools.h"
  5. #include "excludetools.h"
  6. using namespace std;
  7. Strings getExclusions(const KindConfig& conf)
  8. {
  9. Strings exclusions;
  10. if (conf.hasKey("exclude"))
  11. exclusions += conf.getStrings("exclude");
  12. if (conf.getBool("shellMode"))
  13. {
  14. string path = conf.getString("path");
  15. string remoteShell = conf.getString("remoteShell");
  16. string userAtHost = conf.getString("user") + "@" + conf.getString("host");
  17. string rshCommand = remoteShell;
  18. if (remoteShell.empty())
  19. rshCommand = "ssh";
  20. rshCommand += " " + userAtHost;
  21. Strings userExcludeCommands = conf.getStrings("userExcludeCommand");
  22. for (auto cmd : userExcludeCommands)
  23. {
  24. replacePlaceHolder(cmd, "%path", conf.getString("path"));
  25. verbosePrint("looking for exclusions (" + cmd + ")");
  26. int rc;
  27. Strings excludedFiles = remoteExec(rshCommand, cmd, rc, debug);
  28. /*
  29. if (rc > 0)
  30. {
  31. // return Strings should contain error messages
  32. throw Exception("Find excludes", "Search for excludes failed");
  33. }
  34. */
  35. for (unsigned int i = 0; i < excludedFiles.size(); ++i)
  36. {
  37. FileName fn(excludedFiles[i]);
  38. exclusions.push_back('/' + fn.getPath());
  39. debugPrint("Excluding: " + exclusions.back());
  40. }
  41. }
  42. string userExcludeFile = conf.getString("userExcludeFile");
  43. if (!userExcludeFile.empty())
  44. {
  45. userExcludeFile = path + "/" + userExcludeFile;
  46. string getExcludeFileCommand = " \" if [ -f '" + userExcludeFile + "' ]; then ";
  47. getExcludeFileCommand += " cat '" + userExcludeFile + "' ; fi \"";
  48. // cout << getExcludeFileCommand << endl;
  49. int rc;
  50. Strings excludes2 = remoteExec(rshCommand, getExcludeFileCommand, rc, debug);
  51. if (rc == 0)
  52. exclusions += excludes2;
  53. } // if (shellMode)
  54. }
  55. return exclusions;
  56. }