fuse_impls_rmdir.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. #include "fuse_dfs.h"
  19. #include "fuse_impls.h"
  20. #include "fuse_trash.h"
  21. #include "fuse_connect.h"
  22. extern const char *const TrashPrefixDir;
  23. int dfs_rmdir(const char *path)
  24. {
  25. TRACE1("rmdir", path)
  26. dfs_context *dfs = (dfs_context*)fuse_get_context()->private_data;
  27. assert(path);
  28. assert(dfs);
  29. assert('/' == *path);
  30. if (is_protected(path)) {
  31. ERROR("Trying to delete protected directory %s", path);
  32. return -EACCES;
  33. }
  34. if (dfs->read_only) {
  35. ERROR("HDFS configured read-only, cannot delete directory %s", path);
  36. return -EACCES;
  37. }
  38. hdfsFS userFS = doConnectAsUser(dfs->nn_uri, dfs->nn_port);
  39. if (userFS == NULL) {
  40. ERROR("Could not connect");
  41. return -EIO;
  42. }
  43. int ret = 0;
  44. int numEntries = 0;
  45. hdfsFileInfo *info = hdfsListDirectory(userFS,path,&numEntries);
  46. if (info) {
  47. hdfsFreeFileInfo(info, numEntries);
  48. }
  49. if (numEntries) {
  50. ret = -ENOTEMPTY;
  51. goto cleanup;
  52. }
  53. if (hdfsDeleteWithTrash(userFS, path, dfs->usetrash)) {
  54. ERROR("Error trying to delete directory %s", path);
  55. ret = -EIO;
  56. goto cleanup;
  57. }
  58. cleanup:
  59. if (doDisconnect(userFS)) {
  60. ret = -EIO;
  61. }
  62. return ret;
  63. }