You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.7 KiB

6 years ago
6 years ago
  1. /*
  2. Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
  3. Permission to use, copy, modify, and/or distribute this software for any
  4. purpose with or without fee is hereby granted, provided that the above
  5. copyright notice and this permission notice appear in all copies.
  6. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  7. WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  8. MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  9. ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  10. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  11. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  12. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  13. */
  14. #include "errno.hpp"
  15. #include "fs_exists.hpp"
  16. #include "fs_info.hpp"
  17. #include "fs_path.hpp"
  18. #include "policies.hpp"
  19. #include "policy.hpp"
  20. #include "policy_error.hpp"
  21. #include "policy_lfs.hpp"
  22. #include "strvec.hpp"
  23. #include <limits>
  24. #include <string>
  25. using std::string;
  26. namespace lfs
  27. {
  28. static
  29. int
  30. create(const Branches::CPtr &branches_,
  31. StrVec *paths_)
  32. {
  33. int rv;
  34. int error;
  35. uint64_t lfs;
  36. fs::info_t info;
  37. const string *basepath;
  38. error = ENOENT;
  39. lfs = std::numeric_limits<uint64_t>::max();
  40. basepath = NULL;
  41. for(const auto &branch : *branches_)
  42. {
  43. if(branch.ro_or_nc())
  44. error_and_continue(error,EROFS);
  45. rv = fs::info(branch.path,&info);
  46. if(rv == -1)
  47. error_and_continue(error,ENOENT);
  48. if(info.readonly)
  49. error_and_continue(error,EROFS);
  50. if(info.spaceavail < branch.minfreespace())
  51. error_and_continue(error,ENOSPC);
  52. if(info.spaceavail > lfs)
  53. continue;
  54. lfs = info.spaceavail;
  55. basepath = &branch.path;
  56. }
  57. if(basepath == NULL)
  58. return (errno=error,-1);
  59. paths_->push_back(*basepath);
  60. return 0;
  61. }
  62. }
  63. int
  64. Policy::LFS::Action::operator()(const Branches::CPtr &branches_,
  65. const char *fusepath_,
  66. StrVec *paths_) const
  67. {
  68. return Policies::Action::eplfs(branches_,fusepath_,paths_);
  69. }
  70. int
  71. Policy::LFS::Create::operator()(const Branches::CPtr &branches_,
  72. const char *fusepath_,
  73. StrVec *paths_) const
  74. {
  75. return ::lfs::create(branches_,paths_);
  76. }
  77. int
  78. Policy::LFS::Search::operator()(const Branches::CPtr &branches_,
  79. const char *fusepath_,
  80. StrVec *paths_) const
  81. {
  82. return Policies::Search::eplfs(branches_,fusepath_,paths_);
  83. }