Browse Source

build: Fix Shellcheck for get_source_date_epoch.sh

If a `cd` to `TOPDIR` fails the script should quit.

Also unify `try_mtime` function by storing it in a variable.

Signed-off-by: Paul Spooren <[email protected]>
Paul Spooren 5 năm trước cách đây
mục cha
commit
ae87e53e33
1 tập tin đã thay đổi với 5 bổ sung2 xóa
  1. 5 2
      scripts/get_source_date_epoch.sh

+ 5 - 2
scripts/get_source_date_epoch.sh

@@ -1,7 +1,10 @@
 #!/usr/bin/env bash
 export LANG=C
 export LC_ALL=C
-[ -n "$TOPDIR" ] && cd $TOPDIR
+
+if [ -n "$TOPDIR" ]; then
+	cd "$TOPDIR" || exit 1
+fi
 
 try_version() {
 	[ -f version.date ] || return 1
@@ -22,7 +25,7 @@ try_hg() {
 }
 
 try_mtime() {
-	perl -e 'print((stat $ARGV[0])[9])' "$0"
+	SOURCE_DATE_EPOCH=$(perl -e 'print((stat $ARGV[0])[9])' "$0")
 	[ -n "$SOURCE_DATE_EPOCH" ]
 }