fuse_impls_unlink.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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_connect.h"
  21. #include "fuse_trash.h"
  22. int dfs_unlink(const char *path)
  23. {
  24. struct hdfsConn *conn = NULL;
  25. hdfsFS fs;
  26. int ret = 0;
  27. dfs_context *dfs = (dfs_context*)fuse_get_context()->private_data;
  28. TRACE1("unlink", path)
  29. assert(path);
  30. assert(dfs);
  31. assert('/' == *path);
  32. if (is_protected(path)) {
  33. ERROR("Trying to delete protected directory %s", path);
  34. ret = -EACCES;
  35. goto cleanup;
  36. }
  37. ret = fuseConnectAsThreadUid(&conn);
  38. if (ret) {
  39. fprintf(stderr, "fuseConnectAsThreadUid: failed to open a libhdfs "
  40. "connection! error %d.\n", ret);
  41. ret = -EIO;
  42. goto cleanup;
  43. }
  44. fs = hdfsConnGetFs(conn);
  45. if (hdfsDeleteWithTrash(fs, path, dfs->usetrash)) {
  46. ERROR("Could not delete file %s", path);
  47. ret = (errno > 0) ? -errno : -EIO;
  48. goto cleanup;
  49. }
  50. ret = 0;
  51. cleanup:
  52. if (conn) {
  53. hdfsConnRelease(conn);
  54. }
  55. return ret;
  56. }