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.

49 lines
933 B

10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
  1. #include "branch2.hpp"
  2. #include <iostream>
  3. #include <sys/types.h>
  4. #include <sys/stat.h>
  5. #include <fcntl.h>
  6. #include <unistd.h>
  7. Branch2::Branch2()
  8. : enabled(false),
  9. mode(Mode::RW),
  10. min_free_space(0),
  11. fd(-1),
  12. path()
  13. {
  14. }
  15. Branch2::Branch2(Branch2 &&v_)
  16. : enabled(v_.enabled),
  17. mode(v_.mode),
  18. min_free_space(v_.min_free_space),
  19. fd(v_.fd),
  20. path(std::move(v_.path))
  21. {
  22. v_.fd = -1;
  23. }
  24. Branch2::Branch2(toml::value const &v_)
  25. : mode(Mode::RW)
  26. {
  27. enabled = v_.at("enabled").as_boolean();
  28. mode = Mode::_from_string(toml::find<std::string>(v_,"mode").c_str());
  29. min_free_space = toml::find_or<uint64_t>(v_,"min-free-space",0);
  30. path = toml::find<std::string>(v_,"path");
  31. int const flags = O_DIRECTORY | O_PATH | O_NOATIME;
  32. fd = openat(AT_FDCWD,path.string().c_str(),flags);
  33. if(fd < 0)
  34. enabled = false;
  35. }
  36. Branch2::~Branch2()
  37. {
  38. if(fd >= 0)
  39. close(fd);
  40. }