logo

live-bootstrap

Mirror of <https://github.com/fosslinux/live-bootstrap>

touch-dereference.patch (3335B)


  1. SPDX-FileCopyrightText: 2022 Andrius Štikonas <andrius@stikonas.eu>
  2. SPDX-FileCopyrightText: 2009 Eric Blake <ebb9@byu.net>
  3. SPDX-License-Identifier: GPL-2.0-or-later
  4. touch: add -h to change symlink timestamps, where supported
  5. diff -r -U3 coreutils-5.0.orig/src/touch.c coreutils-5.0/src/touch.c
  6. --- coreutils-5.0/src/touch.c 2002-12-20 20:09:22.000000000 +0000
  7. +++ coreutils-5.0/src/touch.c 2022-05-16 20:31:37.801988595 +0100
  8. @@ -77,6 +77,9 @@
  9. /* (-r) If nonzero, use times from a reference file. */
  10. static int use_ref;
  11. +/* (-h) If true, change the times of an existing symlink, if possible. */
  12. +static int no_dereference;
  13. +
  14. /* (-t) If nonzero, date supplied on command line in POSIX format. */
  15. static int posix_date;
  16. @@ -110,6 +113,7 @@
  17. {"date", required_argument, 0, 'd'},
  18. {"file", required_argument, 0, 'r'}, /* FIXME: phase out --file */
  19. {"reference", required_argument, 0, 'r'},
  20. + {"no-dereference", no_argument, NULL, 'h'},
  21. {GETOPT_HELP_OPTION_DECL},
  22. {GETOPT_VERSION_OPTION_DECL},
  23. {0, 0, 0, 0}
  24. @@ -138,7 +142,7 @@
  25. int fd = -1;
  26. int open_errno = 0;
  27. - if (! no_create)
  28. + if (! (no_create || no_dereference))
  29. {
  30. /* Try to open FILE, creating it if necessary. */
  31. fd = open (file, O_WRONLY | O_CREAT | O_NONBLOCK | O_NOCTTY,
  32. @@ -158,7 +162,7 @@
  33. the other one. If we have the file descriptor already, use fstat.
  34. Otherwise, either we're in no-create mode (and hence didn't call open)
  35. or FILE is inaccessible or a directory, so we have to use stat. */
  36. - if (fd != -1 ? fstat (fd, &sbuf) : stat (file, &sbuf))
  37. + if (fd != -1 ? fstat (fd, &sbuf) : (no_dereference ? lstat (file, &sbuf) : stat (file, &sbuf)))
  38. {
  39. if (open_errno)
  40. error (0, open_errno, _("creating %s"), quote (file));
  41. @@ -223,7 +227,7 @@
  42. }
  43. else
  44. {
  45. - if (no_create && errno == ENOENT)
  46. + if ((no_create || no_dereference) && errno == ENOENT)
  47. return 0;
  48. error (0, errno, _("setting times of %s"), quote (file));
  49. }
  50. @@ -254,6 +258,9 @@
  51. -c, --no-create do not create any files\n\
  52. -d, --date=STRING parse STRING and use it instead of current time\n\
  53. -f (ignored)\n\
  54. + -h, --no-dereference affect each symbolic link instead of any referenced\n\
  55. + file (useful only on systems that can change the\n\
  56. + timestamps of a symlink)\n\
  57. -m change only the modification time\n\
  58. "), stdout);
  59. fputs (_("\
  60. @@ -289,7 +296,7 @@
  61. change_times = no_create = use_ref = posix_date = flexible_date = 0;
  62. - while ((c = getopt_long (argc, argv, "acd:fmr:t:", longopts, NULL)) != -1)
  63. + while ((c = getopt_long (argc, argv, "acd:fhmr:t:", longopts, NULL)) != -1)
  64. {
  65. switch (c)
  66. {
  67. @@ -315,6 +322,10 @@
  68. case 'f':
  69. break;
  70. + case 'h':
  71. + no_dereference = true;
  72. + break;
  73. +
  74. case 'm':
  75. change_times |= CH_MTIME;
  76. break;
  77. @@ -358,7 +369,10 @@
  78. if (use_ref)
  79. {
  80. - if (stat (ref_file, &ref_stats))
  81. + /* Don't use (no_dereference ? lstat : stat) (args), since stat
  82. + might be an object-like macro. */
  83. + if (no_dereference ? lstat (ref_file, &ref_stats)
  84. + : stat (ref_file, &ref_stats))
  85. error (EXIT_FAILURE, errno,
  86. _("failed to get attributes of %s"), quote (ref_file));
  87. date_set++;