1
0

fuse_impls_utimens.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. struct hdfsConn *conn = NULL;
  24. hdfsFS fs;
  25. int ret = 0;
  26. dfs_context *dfs = (dfs_context*)fuse_get_context()->private_data;
  27. TRACE1("utimens", path)
  28. assert(path);
  29. assert(dfs);
  30. assert('/' == *path);
  31. time_t aTime = ts[0].tv_sec;
  32. time_t mTime = ts[1].tv_sec;
  33. ret = fuseConnectAsThreadUid(&conn);
  34. if (ret) {
  35. fprintf(stderr, "fuseConnectAsThreadUid: failed to open a libhdfs "
  36. "connection! error %d.\n", ret);
  37. ret = -EIO;
  38. goto cleanup;
  39. }
  40. fs = hdfsConnGetFs(conn);
  41. if (hdfsUtime(fs, path, mTime, aTime)) {
  42. hdfsFileInfo *info = hdfsGetPathInfo(fs, path);
  43. if (info == NULL) {
  44. ret = (errno > 0) ? -errno : -ENOENT;
  45. goto cleanup;
  46. }
  47. // Silently ignore utimens failure for directories, otherwise
  48. // some programs like tar will fail.
  49. if (info->mKind == kObjectKindDirectory) {
  50. ret = 0;
  51. } else {
  52. ret = (errno > 0) ? -errno : -EACCES;
  53. }
  54. goto cleanup;
  55. }
  56. ret = 0;
  57. cleanup:
  58. if (conn) {
  59. hdfsConnRelease(conn);
  60. }
  61. return ret;
  62. }