Sometimes the day of week was being calculated incorretly while vaildating date in check-for-bogus-dates(). The fix eliminates side effects of any surrouding non-printable characters in date fields.
Change-Id: Ib2ccfda24c153f6579299fe85bedc4d306750ca8
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/5899
Tested-by: gerrit-photon <photon-checkins@vmware.com>
Reviewed-by: Alexey Makhalov <amakhalov@vmware.com>
... | ... |
@@ -42,22 +42,28 @@ function check-for-correct-version() |
42 | 42 |
# Changelog should have: |
43 | 43 |
# - correct day of week for the date |
44 | 44 |
# - descending chronological order |
45 |
+# - whitespaces are ignored while validating dates |
|
45 | 46 |
function check-for-bogus-dates() |
46 | 47 |
{ |
47 |
- local IFS=$'\n' |
|
48 |
- local prev_epoch_seconds=`date +%s` |
|
49 |
- for entry in `sed -e '1,/%changelog/d' $i | grep '<' | grep '>' | grep '*' | sed 's/^*//g' | sed 's/ \+/ /g'` ; do |
|
50 |
- IFS=$' ' read D m d y s <<< $entry |
|
51 |
- day=`date --date "$m $d $y" +%a` |
|
48 |
+ local prev_epoch_seconds=$(date +%s) |
|
49 |
+ local D='' |
|
50 |
+ local m='' |
|
51 |
+ local d='' |
|
52 |
+ local y='' |
|
53 |
+ local epoch_seconds='' |
|
54 |
+ |
|
55 |
+ sed -e '1,/%changelog/d' "$1" | grep -v '^[[:space:]]*-' | awk '{printf "%s %s %02d %04d\n", $2, $3, $4, $5}' | \ |
|
56 |
+ while read D m d y |
|
57 |
+ do |
|
58 |
+ day=$(date --date="$m $d $y" '+%a') |
|
52 | 59 |
if [ "${D}" != "${day}" ]; then |
53 |
- echo "ERROR in $1: bogus date in $entry" |
|
54 |
- echo "$m $d $y is $day" |
|
60 |
+ echo "ERROR in $1: bogus date $m $d $y found - actual day is $D, but found $day" |
|
55 | 61 |
exit 1 |
56 | 62 |
fi |
57 |
- epoch_seconds=`date --date "$m $d $y" +%s` |
|
63 |
+ epoch_seconds=$(date --date "$m $d $y" +%s) |
|
58 | 64 |
if [ $prev_epoch_seconds -lt $epoch_seconds ]; then |
59 | 65 |
echo "ERROR in $1: %changelog not in descending chronological order" |
60 |
- echo "Ascending order starts with $entry" |
|
66 |
+ echo "Date validation failed at $D $m $d $y" |
|
61 | 67 |
exit 1 |
62 | 68 |
fi |
63 | 69 |
prev_epoch_seconds=$epoch_seconds |