Mirror of strace – the linux syscall tracer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

file-date-gen 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/bin/sh
  2. #
  3. # Copyright (c) 2017-2019 The strace developers.
  4. # All rights reserved.
  5. #
  6. # SPDX-License-Identifier: LGPL-2.1-or-later
  7. if [ "$1" = "-f" ]; then
  8. shift
  9. DATE_FORMAT="$1"
  10. shift
  11. fi
  12. : ${FILE:=$1}
  13. : ${DATE_FILE:=$(dirname "$FILE")/.$(basename "${FILE}").date}
  14. : ${DEFAULT_DATE:=$2}
  15. : ${DATE_FORMAT:=%Y-%m-%d}
  16. LC_TIME=C; export LC_TIME
  17. date=
  18. [ -n "${FILE}" ] || {
  19. echo >&2 "$0 $(dirname "$0")/file [$(dirname "$0")/file.date [DEFAULT_DATE]]"
  20. exit 1
  21. }
  22. [ -f "${DATE_FILE}" ] && date="$(cat "${DATE_FILE}")"
  23. [ -n "${date}" ] ||
  24. date="$(git log -s -n 1 --format=format:%cD "${FILE}")"
  25. [ -n "${date}" ] ||
  26. date="${DEFAULT_DATE}"
  27. [ -n "${date}" ] ||
  28. [ -z "${SOURCE_DATE_EPOCH-}" ] ||
  29. date="$(date -u -d "@${SOURCE_DATE_EPOCH}")"
  30. [ -n "${date}" ] ||
  31. date="$(date -u)"
  32. [ -n "${date}" ] || {
  33. printf >&2 "%s: Undefined date.\n" "$0"
  34. exit 1
  35. }
  36. datestr="$(date -u "+${DATE_FORMAT}" -d "${date}")" &&
  37. [ -n "${datestr}" ] || {
  38. printf >&2 "%s: Invalid date: %s\n" "$0" "$date"
  39. exit 1
  40. }
  41. exec printf '%s' "$datestr"