fuse_impls_rename.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. int dfs_rename(const char *from, const char *to)
  23. {
  24. struct hdfsConn *conn = NULL;
  25. hdfsFS fs;
  26. dfs_context *dfs = (dfs_context*)fuse_get_context()->private_data;
  27. int ret;
  28. TRACE1("rename", from)
  29. // check params and the context var
  30. assert(from);
  31. assert(to);
  32. assert(dfs);
  33. assert('/' == *from);
  34. assert('/' == *to);
  35. if (is_protected(from) || is_protected(to)) {
  36. ERROR("Could not rename %s to %s", from, to);
  37. return -EACCES;
  38. }
  39. if (dfs->read_only) {
  40. ERROR("HDFS configured read-only, cannot rename directory %s", from);
  41. return -EACCES;
  42. }
  43. ret = fuseConnectAsThreadUid(&conn);
  44. if (ret) {
  45. fprintf(stderr, "fuseConnectAsThreadUid: failed to open a libhdfs "
  46. "connection! error %d.\n", ret);
  47. ret = -EIO;
  48. goto cleanup;
  49. }
  50. fs = hdfsConnGetFs(conn);
  51. if (hdfsRename(fs, from, to)) {
  52. ERROR("Rename %s to %s failed", from, to);
  53. ret = (errno > 0) ? -errno : -EIO;
  54. goto cleanup;
  55. }
  56. ret = 0;
  57. cleanup:
  58. if (conn) {
  59. hdfsConnRelease(conn);
  60. }
  61. return ret;
  62. }