excludetools.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. if (rc > 0)
  29. {
  30. // return Strings should contain error messages
  31. throw Exception("Find excludes", "Search for excludes failed");
  32. }
  33. for (unsigned int i = 0; i < excludedFiles.size(); ++i)
  34. {
  35. FileName fn(excludedFiles[i]);
  36. exclusions.push_back('/' + fn.getPath());
  37. debugPrint("Excluding: " + exclusions.back());
  38. }
  39. }
  40. /*
  41. string userExcludeFile = conf.getString("userExcludeFile");
  42. if (!userExcludeFile.empty())
  43. {
  44. userExcludeFile = path + "/" + userExcludeFile;
  45. string getExcludeFileCommand = " \" if [ -f '" + userExcludeFile + "' ]; then ";
  46. getExcludeFileCommand += " cat '" + userExcludeFile + "' ; fi \"";
  47. // cout << getExcludeFileCommand << endl;
  48. int rc;
  49. Strings excludes2 = remoteExec(rshCommand, getExcludeFileCommand, rc, debug);
  50. if (rc == 0)
  51. exclusions += excludes2;
  52. } // if (shellMode)
  53. */
  54. }
  55. return exclusions;
  56. }