From d705ab93e1ac4073b06db0ce3737b3b6051611c8 Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Mon, 1 Oct 2018 11:47:23 -0700 Subject: [PATCH] Check file permissions in the check_format script Change-Id: I572b24b2f4f149333f2e4b04f6f4961de9c23373 Signed-off-by: Ben Walker Reviewed-on: https://review.gerrithub.io/427539 Reviewed-by: Jim Harris Reviewed-by: Pawel Wodkowski Reviewed-by: Shuhei Matsumoto Tested-by: SPDK CI Jenkins Chandler-Test-Pool: SPDK Automated Test System --- autorun_post.py | 2 +- scripts/check_format.sh | 45 +++++++++++++++++++++++++ scripts/pkgdep.sh | 2 +- scripts/rpc/bdev.py | 0 test/bdev/bdevperf/bdevperf.c | 0 test/common/config/vm_setup.sh | 2 +- test/json_config/common.sh | 0 test/lvol/test_cases.py | 1 - test/pmem/common.sh | 2 -- test/spdkcli/common.sh | 1 - test/unit/lib/bdev/crypto.c/crypto_ut.c | 0 11 files changed, 48 insertions(+), 7 deletions(-) mode change 100755 => 100644 scripts/rpc/bdev.py mode change 100755 => 100644 test/bdev/bdevperf/bdevperf.c mode change 100755 => 100644 test/json_config/common.sh mode change 100755 => 100644 test/unit/lib/bdev/crypto.c/crypto_ut.c diff --git a/autorun_post.py b/autorun_post.py index f64f360c4..1a8810e3f 100755 --- a/autorun_post.py +++ b/autorun_post.py @@ -1,4 +1,4 @@ -#! /usr/bin/python3 +#!/usr/bin/python3 import shutil import subprocess diff --git a/scripts/check_format.sh b/scripts/check_format.sh index 991d3b7a0..3a52a101d 100755 --- a/scripts/check_format.sh +++ b/scripts/check_format.sh @@ -8,6 +8,51 @@ set -e rc=0 +echo -n "Checking file permissions..." + +while read -r perm _res0 _res1 path; do + if [ ! -f "$path" ]; then + continue + fi + + fname=$(basename -- "$path") + + case ${fname##*.} in + c|h|cpp|cc|cxx|hh|hpp|md|html|js|json|svg|Doxyfile|yml|LICENSE|README|conf|in|Makefile|mk|gitignore|go|txt) + # These file types should never be executable + if [ "$perm" -eq 100755 ]; then + echo "ERROR: $path is marked executable but is a code file." + rc=1 + fi + ;; + *) + shebang=$(head -n 1 $path | cut -c1-3) + + # git only tracks the execute bit, so will only ever return 755 or 644 as the permission. + if [ "$perm" -eq 100755 ]; then + # If the file has execute permission, it should start with a shebang. + if [ "$shebang" != "#!/" ]; then + echo "ERROR: $path is marked executable but does not start with a shebang." + rc=1 + fi + else + # If the file doesnot have execute permissions, it should not start with a shebang. + if [ "$shebang" = "#!/" ]; then + echo "ERROR: $path is not marked executable but starts with a shebang." + rc=1 + fi + fi + ;; + esac + +done <<< $(git grep -I --name-only --untracked -e . | git ls-files -s) + +if [ $rc -eq 0 ]; then + echo " OK" +fi + +exit 0 + if hash astyle; then echo -n "Checking coding style..." if [ "$(astyle -V)" \< "Artistic Style Version 3" ] diff --git a/scripts/pkgdep.sh b/scripts/pkgdep.sh index da7181e95..f1ee48f46 100755 --- a/scripts/pkgdep.sh +++ b/scripts/pkgdep.sh @@ -1,4 +1,4 @@ -#! /usr/bin/env bash +#!/usr/bin/env bash # Please run this script as root. set -e diff --git a/scripts/rpc/bdev.py b/scripts/rpc/bdev.py old mode 100755 new mode 100644 diff --git a/test/bdev/bdevperf/bdevperf.c b/test/bdev/bdevperf/bdevperf.c old mode 100755 new mode 100644 diff --git a/test/common/config/vm_setup.sh b/test/common/config/vm_setup.sh index a685c4b9f..e01b88790 100755 --- a/test/common/config/vm_setup.sh +++ b/test/common/config/vm_setup.sh @@ -1,4 +1,4 @@ -#! /usr/bin/env bash +#!/usr/bin/env bash # Virtual Machine environment requirements: # 8 GiB of RAM (for DPDK) diff --git a/test/json_config/common.sh b/test/json_config/common.sh old mode 100755 new mode 100644 diff --git a/test/lvol/test_cases.py b/test/lvol/test_cases.py index 9da564a68..ad85f529d 100644 --- a/test/lvol/test_cases.py +++ b/test/lvol/test_cases.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 import io import time import sys diff --git a/test/pmem/common.sh b/test/pmem/common.sh index e95a6888b..add36719a 100644 --- a/test/pmem/common.sh +++ b/test/pmem/common.sh @@ -1,5 +1,3 @@ -#!/usr/bin/env bash - BASE_DIR=$(readlink -f $(dirname $0)) [[ -z "$TEST_DIR" ]] && TEST_DIR="$(cd $BASE_DIR/../../ && pwd)" rpc_py="$TEST_DIR/scripts/rpc.py " diff --git a/test/spdkcli/common.sh b/test/spdkcli/common.sh index b55ba7051..da61e6f57 100644 --- a/test/spdkcli/common.sh +++ b/test/spdkcli/common.sh @@ -1,4 +1,3 @@ -#!/usr/bin/env bash set -xe testdir=$(readlink -f $(dirname $0)) diff --git a/test/unit/lib/bdev/crypto.c/crypto_ut.c b/test/unit/lib/bdev/crypto.c/crypto_ut.c old mode 100755 new mode 100644