Guest User

Untitled

a guest
Jan 24th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. void Dirs::scan_dir(string dir_name, DataBase &b, string owner) {
  2. fs::path p(dir_name);
  3. if (!fs::exists(p)) {
  4. std::cout<<"Path does not exist"<<std::endl;
  5. return;
  6. }
  7. if(fs::is_directory(p)) {
  8. fs::recursive_directory_iterator end_iter;
  9. std::vector<std::string> check_link;
  10. for(fs::recursive_directory_iterator begin(p); begin != end_iter; ++begin){
  11. try {
  12. fs::path tmp = begin->path().filename();
  13. string f_path = begin->path().relative_path().string();
  14. f_path = "/" + f_path;
  15. bool link_found = false;
  16. for(std::vector<std::string>::iterator it = check_link.begin();
  17. it != check_link.end(); ++it) {
  18. if (f_path.find(*it) != std::string::npos){
  19. link_found = true;
  20. std::cout<<"link name"<<*it<<" in path is "<<f_path<<std::endl;
  21. break;
  22. }
  23. }
  24. if(link_found)
  25. continue;
  26. if(fs::is_symlink(begin->path())) {
  27. check_link.push_back(begin->path().filename());
  28. continue;
  29. }
  30.  
  31. if(fs::is_regular_file(begin->path())) {
  32. std::vector<std::string> ls_file_output = this->getfiledetail(f_path);
  33. string f_time = std::to_string(fs::last_write_time(begin->path()));
  34. #if 1
  35. b.insert_disk_analyze_query(ls_file_output[2],
  36. this->local_time(),
  37. tmp.string(),
  38. f_path,
  39. ls_file_output[3],
  40. f_time);
  41. #endif
  42. }
  43. }
  44. catch(fs::filesystem_error &ex) {
  45. std::cout<<" File.."<<ex.what()<<std::endl;
  46. signal(SIGINT, signal_callback_handler);
  47. }
  48. catch(const std::exception &ex) {
  49. std::cout << ex.what() << std::endl;
  50. }
  51. catch(...) {
  52. std::cout<<"unkown error"<<std::endl;
  53. }
  54. }
  55. }
  56. }
Add Comment
Please, Sign In to add comment