From 02467edd88623ef5345402566319867f5fbef84a Mon Sep 17 00:00:00 2001 From: Mark Beierl Date: Thu, 11 Aug 2022 21:59:11 -0400 Subject: [PATCH] Bug 2137: Improve license check Rather than relying on a case sensitive extension (.jpg, etc) this change introduces the use of file mime-type to better determine if a file requires a license or not. Change-Id: I24492c584c0d124c47d542cb8f8019ae56642682 Signed-off-by: Mark Beierl --- tools/license_scan.sh | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/tools/license_scan.sh b/tools/license_scan.sh index b20bb0af..a7946360 100755 --- a/tools/license_scan.sh +++ b/tools/license_scan.sh @@ -22,15 +22,31 @@ exception_list="':(exclude)*.pdf' ':(exclude)*.png' ':(exclude)*.jpeg' ':(exclud git fetch for file in $(echo ${exception_list} | xargs git diff --name-only origin/$GERRIT_BRANCH -- . ); do - license="No Apache license found" - if [ -f $file ]; then - if [ -s $file ]; then - if [ $(grep -c "http://www.apache.org/licenses/LICENSE-2.0" $file) -ge 1 ] ; then - license="Apache-2.0" + + file_type=$(file -b --mime-type $file | sed 's|/.*||') + echo $file is $file_type + case "$file_type" in + text) + binary=false + ;; + *) + binary=true + ;; + esac + + if $binary ; then + license=Binary + else + license="No Apache license found" + if [ -f $file ]; then + if [ -s $file ]; then + if [ $(grep -c "http://www.apache.org/licenses/LICENSE-2.0" $file) -ge 1 ] ; then + license="Apache-2.0" + fi fi + else + license="DELETED" fi - else - license="DELETED" fi echo "$file $license" case "$license" in @@ -42,6 +58,8 @@ for file in $(echo ${exception_list} | xargs git diff --name-only origin/$GERRIT ;; "DELETED") ;; + "Binary") + ;; *) echo "BAD LICENSE ON FILE $file" other=$((other + 1)) -- 2.25.1