fuse_impls_rmdir.c 2.0 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. struct hdfsConn *conn = NULL;
  26. hdfsFS fs;
  27. int ret;
  28. dfs_context *dfs = (dfs_context*)fuse_get_context()->private_data;
  29. int numEntries = 0;
  30. hdfsFileInfo *info = NULL;
  31. TRACE1("rmdir", path)
  32. assert(path);
  33. assert(dfs);
  34. assert('/' == *path);
  35. if (is_protected(path)) {
  36. ERROR("Trying to delete protected directory %s", path);
  37. ret = -EACCES;
  38. goto cleanup;
  39. }
  40. ret = fuseConnectAsThreadUid(&conn);
  41. if (ret) {
  42. fprintf(stderr, "fuseConnectAsThreadUid: failed to open a libhdfs "
  43. "connection! error %d.\n", ret);
  44. ret = -EIO;
  45. goto cleanup;
  46. }
  47. fs = hdfsConnGetFs(conn);
  48. info = hdfsListDirectory(fs, path, &numEntries);
  49. if (numEntries) {
  50. ret = -ENOTEMPTY;
  51. goto cleanup;
  52. }
  53. if (hdfsDeleteWithTrash(fs, path, dfs->usetrash)) {
  54. ERROR("Error trying to delete directory %s", path);
  55. ret = -EIO;
  56. goto cleanup;
  57. }
  58. ret = 0;
  59. cleanup:
  60. if (info) {
  61. hdfsFreeFileInfo(info, numEntries);
  62. }
  63. if (conn) {
  64. hdfsConnRelease(conn);
  65. }
  66. return ret;
  67. }