excludetools.cpp 2.1 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. /*
  43. string userExcludeFile = conf.getString("userExcludeFile");
  44. if (!userExcludeFile.empty())
  45. {
  46. userExcludeFile = path + "/" + userExcludeFile;
  47. string getExcludeFileCommand = " \" if [ -f '" + userExcludeFile + "' ]; then ";
  48. getExcludeFileCommand += " cat '" + userExcludeFile + "' ; fi \"";
  49. // cout << getExcludeFileCommand << endl;
  50. int rc;
  51. Strings excludes2 = remoteExec(rshCommand, getExcludeFileCommand, rc, debug);
  52. if (rc == 0)
  53. exclusions += excludes2;
  54. } // if (shellMode)
  55. */
  56. }
  57. return exclusions;
  58. }