fuse_impls_utimens.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. int dfs_utimens(const char *path, const struct timespec ts[2])
  22. {
  23. TRACE1("utimens", path)
  24. int ret = 0;
  25. dfs_context *dfs = (dfs_context*)fuse_get_context()->private_data;
  26. assert(path);
  27. assert(dfs);
  28. assert('/' == *path);
  29. time_t aTime = ts[0].tv_sec;
  30. time_t mTime = ts[1].tv_sec;
  31. hdfsFS userFS = doConnectAsUser(dfs->nn_uri, dfs->nn_port);
  32. if (userFS == NULL) {
  33. ERROR("Could not connect");
  34. return -EIO;
  35. }
  36. if (hdfsUtime(userFS, path, mTime, aTime)) {
  37. hdfsFileInfo *info = hdfsGetPathInfo(userFS, path);
  38. if (info == NULL) {
  39. ret = (errno > 0) ? -errno : -ENOENT;
  40. goto cleanup;
  41. }
  42. // Silently ignore utimens failure for directories, otherwise
  43. // some programs like tar will fail.
  44. if (info->mKind == kObjectKindDirectory) {
  45. ret = 0;
  46. } else {
  47. ret = (errno > 0) ? -errno : -EACCES;
  48. }
  49. goto cleanup;
  50. }
  51. cleanup:
  52. if (doDisconnect(userFS)) {
  53. ret = -EIO;
  54. }
  55. return ret;
  56. }