hdfs-rm.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #ifndef LIBHDFSPP_TOOLS_HDFS_RM
  19. #define LIBHDFSPP_TOOLS_HDFS_RM
  20. #include <string>
  21. #include <boost/program_options.hpp>
  22. #include "hdfs-tool.h"
  23. namespace hdfs::tools {
  24. /**
  25. * {@class Rm} is an {@class HdfsTool} that removes/unlinks the files or
  26. * directories.
  27. */
  28. class Rm : public HdfsTool {
  29. public:
  30. /**
  31. * {@inheritdoc}
  32. */
  33. Rm(int argc, char **argv);
  34. // Abiding to the Rule of 5
  35. Rm(const Rm &) = default;
  36. Rm(Rm &&) = default;
  37. Rm &operator=(const Rm &) = delete;
  38. Rm &operator=(Rm &&) = delete;
  39. ~Rm() override = default;
  40. /**
  41. * {@inheritdoc}
  42. */
  43. [[nodiscard]] std::string GetDescription() const override;
  44. /**
  45. * {@inheritdoc}
  46. */
  47. [[nodiscard]] bool Do() override;
  48. protected:
  49. /**
  50. * {@inheritdoc}
  51. */
  52. [[nodiscard]] bool Initialize() override;
  53. /**
  54. * {@inheritdoc}
  55. */
  56. [[nodiscard]] bool ValidateConstraints() const override { return argc_ > 1; }
  57. /**
  58. * {@inheritdoc}
  59. */
  60. [[nodiscard]] bool HandleHelp() const override;
  61. /**
  62. * Handle the path argument that's passed to this tool.
  63. *
  64. * @param recursive Perform this operation recursively on the sub-directories.
  65. * @param path The path to the file/directory that needs to be removed.
  66. *
  67. * @return A boolean indicating the result of this operation.
  68. */
  69. [[nodiscard]] virtual bool HandlePath(bool recursive,
  70. const std::string &path) const;
  71. private:
  72. /**
  73. * A boost data-structure containing the description of positional arguments
  74. * passed to the command-line.
  75. */
  76. po::positional_options_description pos_opt_desc_;
  77. };
  78. } // namespace hdfs::tools
  79. #endif